diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift b/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift index 30f73415a..784ab6501 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift @@ -10,7 +10,8 @@ extension DataSourceFacade { static func responseToUserViewButtonAction( dependency: NeedsDependency & AuthContextProvider, user: ManagedObjectRecord, - buttonState: UserView.ButtonState + buttonState: UserView.ButtonState, + viewModel: FollowedBlockedUserIdProviding ) async throws { switch buttonState { case .follow, .unfollow: @@ -18,13 +19,23 @@ extension DataSourceFacade { dependency: dependency, user: user ) + fetchFollowedBlockedUserIds(in: viewModel) case .blocked: try await DataSourceFacade.responseToUserBlockAction( dependency: dependency, user: user ) + fetchFollowedBlockedUserIds(in: viewModel) case .none, .loading: break //no-op } } + + private static func fetchFollowedBlockedUserIds(in viewModel: FollowedBlockedUserIdProviding) { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed + Task { @MainActor in + try await viewModel.fetchFollowedBlockedUserIds() + } + } + } } diff --git a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift index a43757575..c494de9cd 100644 --- a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift +++ b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift @@ -99,14 +99,9 @@ extension FamiliarFollowersViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.tableView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift b/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift index d2dfd7054..4ddb0d5ed 100644 --- a/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift +++ b/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift @@ -125,14 +125,9 @@ extension FollowerListViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.tableView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Profile/Following/FollowingListViewController.swift b/Mastodon/Scene/Profile/Following/FollowingListViewController.swift index f329cf63a..1ece43c32 100644 --- a/Mastodon/Scene/Profile/Following/FollowingListViewController.swift +++ b/Mastodon/Scene/Profile/Following/FollowingListViewController.swift @@ -123,14 +123,9 @@ extension FollowingListViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.tableView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift b/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift index 3b039f677..9ec591112 100644 --- a/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift +++ b/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift @@ -117,14 +117,9 @@ extension FavoritedByViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.tableView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift b/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift index a34807d00..d9803d7ab 100644 --- a/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift +++ b/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift @@ -117,14 +117,9 @@ extension RebloggedByViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.tableView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift index 0d74faa48..74f41f42b 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift @@ -136,14 +136,9 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.collectionView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift index d559d5887..6d52292e0 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift @@ -265,14 +265,9 @@ extension SearchResultViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state + buttonState: state, + viewModel: viewModel ) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await self.viewModel.fetchFollowedBlockedUserIds() - self.tableView.reloadData() - } - } } } } diff --git a/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift b/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift index bfb357765..c8d2f2cd0 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell+ViewModel.swift @@ -59,7 +59,6 @@ extension UserTableViewCell { .debounce(for: 0.1, scheduler: DispatchQueue.main) .receive(on: DispatchQueue.main) .sink { [weak self] followed, blocked in - print(">>> followed.count", followed.count) if blocked.contains(user.id) { self?.userView.setButtonState(.blocked) } else if followed.contains(user.id) { diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift index ae53e3891..120a3bbeb 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift @@ -270,23 +270,28 @@ public extension UserView { switch state { case .loading: - followButton.setTitle(nil, for: .normal) - followButton.setBackgroundColor(Asset.Colors.disabled.color, for: .normal) + followButton.isHidden = true + case .follow: + followButton.isHidden = false followButton.setTitle(L10n.Common.Controls.Friendship.follow, for: .normal) followButton.setBackgroundColor(Asset.Colors.Button.userFollow.color, for: .normal) followButton.setTitleColor(.white, for: .normal) + case .unfollow: + followButton.isHidden = false followButton.setTitle(L10n.Common.Controls.Friendship.following, for: .normal) followButton.setBackgroundColor(Asset.Colors.Button.userFollowing.color, for: .normal) followButton.setTitleColor(Asset.Colors.Button.userFollowingTitle.color, for: .normal) + case .blocked: + followButton.isHidden = false followButton.setTitle(L10n.Common.Controls.Friendship.blocked, for: .normal) followButton.setBackgroundColor(Asset.Colors.Button.userBlocked.color, for: .normal) followButton.setTitleColor(.systemRed, for: .normal) case .none: - break + followButton.isHidden = true } followButton.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)