Don't show Show Reblogs action for non-followed people

This commit is contained in:
Shadowfacts 2023-05-10 22:22:37 -04:00
parent ca03cf3b08
commit 566c3d474d
1 changed files with 14 additions and 5 deletions

View File

@ -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 return UIDeferredMenuElement.uncached({ @MainActor elementHandler in
// workaround for #198, may result in showing outdated relationship, so only do so where necessary // workaround for #198, may result in showing outdated relationship, so only do so where necessary
if !fetch || ProcessInfo.processInfo.isiOSAppOnMac, if !fetch || ProcessInfo.processInfo.isiOSAppOnMac,
let mo = mastodonController.persistentContainer.relationship(forAccount: accountID) { let mo = mastodonController.persistentContainer.relationship(forAccount: accountID) {
elementHandler([builder(mo, mastodonController)]) if let action = builder(mo, mastodonController) {
elementHandler([action])
} else {
elementHandler([])
}
} else { } else {
let relationship = Task { let relationship = Task {
await fetchRelationship(accountID: accountID, mastodonController: mastodonController) await fetchRelationship(accountID: accountID, mastodonController: mastodonController)
} }
Task { @MainActor in Task { @MainActor in
if let relationship = await relationship.value { if let relationship = await relationship.value,
elementHandler([builder(relationship, mastodonController)]) let action = builder(relationship, mastodonController) {
elementHandler([action])
} else { } else {
elementHandler([]) elementHandler([])
} }
@ -549,7 +554,11 @@ extension MenuActionProvider {
} }
@MainActor @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" let title = relationship.showingReblogs ? "Hide Reblogs" : "Show Reblogs"
// todo: need alternate repeat icon to use here // todo: need alternate repeat icon to use here
return UIAction(title: title, image: nil) { [weak self] _ in return UIAction(title: title, image: nil) { [weak self] _ in