Improve follow/unbutton behavior (IOS-140)

This commit is contained in:
Marcus Kida 2023-05-08 16:41:29 +02:00
parent d253143969
commit 096b1200b0
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
10 changed files with 34 additions and 54 deletions

View File

@ -10,7 +10,8 @@ extension DataSourceFacade {
static func responseToUserViewButtonAction(
dependency: NeedsDependency & AuthContextProvider,
user: ManagedObjectRecord<MastodonUser>,
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()
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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()
}
}
}
}
}

View File

@ -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) {

View File

@ -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)