From 566c3d474d7562311e943f8f44f4cd5a64ca283b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 10 May 2023 22:22:37 -0400 Subject: [PATCH] Don't show Show Reblogs action for non-followed people --- Tusker/Screens/Utilities/Previewing.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index f50f1568..148444bf 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -428,19 +428,24 @@ extension MenuActionProvider { } } - private func relationshipAction(_ fetch: Bool, accountID: String, mastodonController: MastodonController, builder: @escaping @MainActor (RelationshipMO, MastodonController) -> UIMenuElement) -> UIDeferredMenuElement { + private func relationshipAction(_ fetch: Bool, accountID: String, mastodonController: MastodonController, builder: @escaping @MainActor (RelationshipMO, MastodonController) -> UIMenuElement?) -> UIDeferredMenuElement { return UIDeferredMenuElement.uncached({ @MainActor elementHandler in // workaround for #198, may result in showing outdated relationship, so only do so where necessary if !fetch || ProcessInfo.processInfo.isiOSAppOnMac, let mo = mastodonController.persistentContainer.relationship(forAccount: accountID) { - elementHandler([builder(mo, mastodonController)]) + if let action = builder(mo, mastodonController) { + elementHandler([action]) + } else { + elementHandler([]) + } } else { let relationship = Task { await fetchRelationship(accountID: accountID, mastodonController: mastodonController) } Task { @MainActor in - if let relationship = await relationship.value { - elementHandler([builder(relationship, mastodonController)]) + if let relationship = await relationship.value, + let action = builder(relationship, mastodonController) { + elementHandler([action]) } else { elementHandler([]) } @@ -549,7 +554,11 @@ extension MenuActionProvider { } @MainActor - private func hideReblogsAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement { + private func hideReblogsAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement? { + // don't show action for people that the user isn't following and isn't already hiding reblogs for + guard relationship.following || relationship.showingReblogs else { + return nil + } let title = relationship.showingReblogs ? "Hide Reblogs" : "Show Reblogs" // todo: need alternate repeat icon to use here return UIAction(title: title, image: nil) { [weak self] _ in