Update profile-screen when relationship changes on user list (IOS-192)
This commit is contained in:
parent
03e9ed7e80
commit
a1ba189822
|
@ -1061,21 +1061,20 @@ extension ProfileViewController {
|
||||||
@objc
|
@objc
|
||||||
func relationshipChanged(_ notification: Notification) {
|
func relationshipChanged(_ notification: Notification) {
|
||||||
|
|
||||||
guard let userInfo = notification.userInfo,
|
guard let userInfo = notification.userInfo else {
|
||||||
let account = userInfo["account"] as? Mastodon.Entity.Account,
|
|
||||||
let me = userInfo["me"] as? Mastodon.Entity.Account,
|
|
||||||
let relationship = userInfo["relationship"] as? Mastodon.Entity.Relationship else {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if account == viewModel.account {
|
if let account = userInfo["account"] as? Mastodon.Entity.Account, account == viewModel.account {
|
||||||
viewModel.account = account
|
viewModel.account = account
|
||||||
}
|
}
|
||||||
|
|
||||||
if me == viewModel.me {
|
if let me = userInfo["me"] as? Mastodon.Entity.Account, me == viewModel.me {
|
||||||
viewModel.me = me
|
viewModel.me = me
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.relationship = relationship
|
if let relationship = userInfo["relationship"] as? Mastodon.Entity.Relationship {
|
||||||
|
viewModel.relationship = relationship
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,10 @@ extension UserTableViewCellDelegate where Self: NeedsDependency & AuthContextPro
|
||||||
// Otherwise the relationship might still be `pending`
|
// Otherwise the relationship might still be `pending`
|
||||||
try await Task.sleep(for: .seconds(1))
|
try await Task.sleep(for: .seconds(1))
|
||||||
|
|
||||||
let relationship = try await self.context.apiService.relationship(forAccounts: [account], authenticationBox: authContext.mastodonAuthenticationBox).value.first
|
guard let relationship = try await self.context.apiService.relationship(forAccounts: [account], authenticationBox: authContext.mastodonAuthenticationBox).value.first,
|
||||||
|
let updatedAccount = try await context.apiService.fetchUser(username: account.acct, domain: account.domain ?? "", authenticationBox: authContext.mastodonAuthenticationBox) else { return }
|
||||||
|
|
||||||
|
let updatedMe = try await context.apiService.authenticatedUserInfo(authenticationBox: authContext.mastodonAuthenticationBox).value
|
||||||
|
|
||||||
let isMe: Bool
|
let isMe: Bool
|
||||||
if let me {
|
if let me {
|
||||||
|
@ -74,6 +77,14 @@ extension UserTableViewCellDelegate where Self: NeedsDependency & AuthContextPro
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
view.viewModel.relationship = relationship
|
view.viewModel.relationship = relationship
|
||||||
view.updateButtonState(with: relationship, isMe: isMe)
|
view.updateButtonState(with: relationship, isMe: isMe)
|
||||||
|
|
||||||
|
let userInfo = [
|
||||||
|
"account": updatedAccount,
|
||||||
|
"relationship": relationship,
|
||||||
|
"me": updatedMe
|
||||||
|
]
|
||||||
|
|
||||||
|
NotificationCenter.default.post(name: .relationshipChanged, object: self, userInfo: userInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue