From 6cf5134ff68adf35712a058b29eec2eeac3f79e0 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Mon, 20 Nov 2023 13:59:25 +0100 Subject: [PATCH] Properly update button-state when following people (IOS-194) --- Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift | 9 ++++++--- .../Discovery/ForYou/DiscoveryForYouViewController.swift | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift index 6fe0005a0..6711380b8 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift @@ -30,15 +30,18 @@ extension DataSourceFacade { static func responseToUserFollowAction( dependency: NeedsDependency & AuthContextProvider, user: Mastodon.Entity.Account - ) async throws { + ) async throws -> Mastodon.Entity.Relationship { let selectionFeedbackGenerator = await UISelectionFeedbackGenerator() await selectionFeedbackGenerator.selectionChanged() - _ = try await dependency.context.apiService.toggleFollow( + let response = try await dependency.context.apiService.toggleFollow( user: user, authenticationBox: dependency.authContext.mastodonAuthenticationBox - ) + ).value + dependency.context.authenticationService.fetchFollowingAndBlockedAsync() + + return response } } diff --git a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift index 8d1b947be..7e9e21641 100644 --- a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift +++ b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift @@ -115,8 +115,14 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate { guard let indexPath = tableView.indexPath(for: cell) else { return } guard case let .account(account, _) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } + cell.profileCardView.setButtonState(.loading) + Task { - try await DataSourceFacade.responseToUserFollowAction(dependency: self, user: account) + let newRelationship = try await DataSourceFacade.responseToUserFollowAction(dependency: self, user: account) + + await MainActor.run { + cell.profileCardView.updateButtonState(with: newRelationship, isMe: false) + } } }