Re-enable pending-check (IOS-192)

This commit is contained in:
Nathan Mattes 2023-12-28 23:32:20 +01:00
parent c0e08c4482
commit 11235f3f75
3 changed files with 34 additions and 52 deletions

View File

@ -268,7 +268,7 @@ extension ProfileHeaderView.ViewModel {
$isRelationshipActionButtonHidden
.assign(to: \.isHidden, on: view.relationshipActionButtonShadowContainer)
.store(in: &disposeBag)
#warning("TODO: Implement")
Publishers.CombineLatest3(
Publishers.CombineLatest3($me, $account, $relationship).eraseToAnyPublisher(),
$isEditing,
@ -280,13 +280,6 @@ extension ProfileHeaderView.ViewModel {
guard let relationship else { return }
view.relationshipActionButton.configure(relationship: relationship, between: account, and: me, isEditing: isEditing, isUpdating: isUpdating)
// if relationshipActionOptionSet.contains(.edit) {
// // check .edit state and set .editing when isEditing
// view.relationshipActionButton.configure(actionOptionSet: isUpdating ? .updating : (isEditing ? .editing : .edit))
// view.configure(state: isEditing ? .editing : .normal)
// } else {
// view.relationshipActionButton.configure(actionOptionSet: relationshipActionOptionSet)
// }
}
.store(in: &disposeBag)
}

View File

@ -124,37 +124,38 @@ class ProfileViewModel: NSObject {
}
.store(in: &disposeBag)
// query relationship
#warning("TODO: Implement")
// let pendingRetryPublisher = CurrentValueSubject<TimeInterval, Never>(1)
// // observe friendship
// Publishers.CombineLatest(
// account,
// pendingRetryPublisher
// )
// .sink { [weak self] account, _ in
// guard let self, let account else { return }
//
// Task {
// do {
// let response = try await self.updateRelationship(
// account: account,
// authenticationBox: self.authContext.mastodonAuthenticationBox
// )
// // there are seconds delay after request follow before requested -> following. Query again when needs
// guard let relationship = response.value.first else { return }
// if relationship.requested == true {
// let delay = pendingRetryPublisher.value
// DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
// guard let _ = self else { return }
// pendingRetryPublisher.value = min(2 * delay, 60)
// }
// }
// } catch {
// }
// } // end Task
// }
// .store(in: &disposeBag)
let pendingRetryPublisher = CurrentValueSubject<TimeInterval, Never>(1)
// observe friendship
Publishers.CombineLatest(
$account,
pendingRetryPublisher
)
.sink { [weak self] account, _ in
guard let self else { return }
Task {
do {
let response = try await self.context.apiService.relationship(
forAccounts: [account],
authenticationBox: self.authContext.mastodonAuthenticationBox
)
// there are seconds delay after request follow before requested -> following. Query again when needs
guard let relationship = response.value.first else { return }
if relationship.requested == true {
let delay = pendingRetryPublisher.value
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
guard let _ = self else { return }
pendingRetryPublisher.value = min(2 * delay, 60)
}
}
} catch {
}
} // end Task
}
.store(in: &disposeBag)
let isBlockingOrBlocked = Publishers.CombineLatest3(
(relationship?.blocking ?? false).publisher,
@ -182,18 +183,6 @@ class ProfileViewModel: NSObject {
let authorization = Mastodon.API.OAuth.Authorization(accessToken: mastodonAuthentication.userAccessToken)
return context.apiService.accountVerifyCredentials(domain: domain, authorization: authorization)
}
private func updateRelationship(
account: Mastodon.Entity.Account,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Relationship]> {
let response = try await context.apiService.relationship(
forAccounts: [account],
authenticationBox: authenticationBox
)
return response
}
}
extension ProfileViewModel {

View File

@ -90,8 +90,8 @@ extension SuggestionAccountViewController: UITableViewDelegate {
guard let tableViewDiffableDataSource = viewModel.tableViewDiffableDataSource else { return }
guard let item = tableViewDiffableDataSource.itemIdentifier(for: indexPath) else { return }
switch item {
case .account(let account, _):
Task { await DataSourceFacade.coordinateToProfileScene(provider: self, account: account) }
case .account(let account, _):
DataSourceFacade.coordinateToProfileScene(provider: self, account: account)
}
tableView.deselectRow(at: indexPath, animated: true)