diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index d99c6cd5d..50efca93d 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -1061,21 +1061,20 @@ extension ProfileViewController { @objc func relationshipChanged(_ notification: Notification) { - guard let userInfo = notification.userInfo, - 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 { + guard let userInfo = notification.userInfo else { return } - if account == viewModel.account { + if let account = userInfo["account"] as? Mastodon.Entity.Account, account == viewModel.account { viewModel.account = account } - if me == viewModel.me { + if let me = userInfo["me"] as? Mastodon.Entity.Account, me == viewModel.me { viewModel.me = me } - viewModel.relationship = relationship + if let relationship = userInfo["relationship"] as? Mastodon.Entity.Relationship { + viewModel.relationship = relationship + } } } diff --git a/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift b/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift index ffb927166..86daa2c21 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift @@ -62,7 +62,10 @@ extension UserTableViewCellDelegate where Self: NeedsDependency & AuthContextPro // Otherwise the relationship might still be `pending` 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 if let me { @@ -74,6 +77,14 @@ extension UserTableViewCellDelegate where Self: NeedsDependency & AuthContextPro await MainActor.run { view.viewModel.relationship = relationship view.updateButtonState(with: relationship, isMe: isMe) + + let userInfo = [ + "account": updatedAccount, + "relationship": relationship, + "me": updatedMe + ] + + NotificationCenter.default.post(name: .relationshipChanged, object: self, userInfo: userInfo) } }