From 746d70f3e061207b556ec91e0675b2fbee5e55a8 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Sun, 6 Nov 2022 10:16:56 +0100 Subject: [PATCH] [WIP] Show show/hide-reblog-menu-entry only for people you already follow (#365) Please consider this WIP, as the breaks the ProfileRelationshipActionButton, somethingsomething RelationshipActionOptionSet for whatever reason, I assume. Also: fixed some typos and warnings. --- .../Scene/Profile/ProfileViewController.swift | 30 +++++++++++-------- .../ViewModel/RelationshipViewModel.swift | 4 +-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index dcaefccb7..c1c5ccea7 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -376,14 +376,20 @@ extension ProfileViewController { } let name = user.displayNameWithFallback let _ = ManagedObjectRecord(objectID: user.objectID) + + var menuActions: [MastodonMenu.Action] = [ + .muteUser(.init(name: name, isMuting: self.viewModel.relationshipViewModel.isMuting)), + .blockUser(.init(name: name, isBlocking: self.viewModel.relationshipViewModel.isBlocking)), + .reportUser(.init(name: name)), + .shareUser(.init(name: name)), + ] + + if let me = self.viewModel?.me, me.following.contains(user) { + menuActions.insert(.hideReblogs(.init(showReblogs: self.viewModel.relationshipViewModel.showReblogs)), at: 1) + } + let menu = MastodonMenu.setupMenu( - actions: [ - .muteUser(.init(name: name, isMuting: self.viewModel.relationshipViewModel.isMuting)), - .hideReblogs(.init(showReblogs: self.viewModel.relationshipViewModel.showReblogs)), - .blockUser(.init(name: name, isBlocking: self.viewModel.relationshipViewModel.isBlocking)), - .reportUser(.init(name: name)), - .shareUser(.init(name: name)), - ], + actions: menuActions, delegate: self ) return menu @@ -743,7 +749,7 @@ extension ProfileViewController: ProfileHeaderViewControllerDelegate { let alertController = UIAlertController(for: error, title: L10n.Common.Alerts.EditProfileFailure.title, preferredStyle: .alert) let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default, handler: nil) alertController.addAction(okAction) - self.coordinator.present( + _ = self.coordinator.present( scene: .alertController(alertController: alertController), from: nil, transition: .alertController(animated: true, completion: nil) @@ -766,11 +772,11 @@ extension ProfileViewController: ProfileHeaderViewControllerDelegate { break case .follow, .request, .pending, .following: guard let user = viewModel.user else { return } - let reocrd = ManagedObjectRecord(objectID: user.objectID) + let record = ManagedObjectRecord(objectID: user.objectID) Task { try await DataSourceFacade.responseToUserFollowAction( dependency: self, - user: reocrd + user: record ) } case .muting: @@ -819,10 +825,8 @@ extension ProfileViewController: ProfileHeaderViewControllerDelegate { let cancelAction = UIAlertAction(title: L10n.Common.Controls.Actions.cancel, style: .cancel, handler: nil) alertController.addAction(cancelAction) present(alertController, animated: true, completion: nil) - case .blocked: + case .blocked, .showReblogs, .isMyself,.followingBy, .blockingBy, .suspended, .edit, .editing, .updating: break - default: - assertionFailure() } } diff --git a/MastodonSDK/Sources/MastodonUI/ViewModel/RelationshipViewModel.swift b/MastodonSDK/Sources/MastodonUI/ViewModel/RelationshipViewModel.swift index d51737b1e..059ef0413 100644 --- a/MastodonSDK/Sources/MastodonUI/ViewModel/RelationshipViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/ViewModel/RelationshipViewModel.swift @@ -92,7 +92,7 @@ public struct RelationshipActionOptionSet: OptionSet { case .edit: return L10n.Common.Controls.Friendship.editInfo case .editing: return L10n.Common.Controls.Actions.done case .updating: return " " - case .showReblogs: return "" + case .showReblogs: return " " } } } @@ -219,7 +219,7 @@ extension RelationshipViewModel { let isMuting = user.mutingBy.contains(me) let isBlockingBy = me.blockingBy.contains(user) let isBlocking = user.blockingBy.contains(me) - let isShowingReblogs = me.showingReblogsBy.contains(user)// user.showingReblogsBy.contains(me) + let isShowingReblogs = me.showingReblogsBy.contains(user) var optionSet: RelationshipActionOptionSet = [.follow]