From e11784904b9c352f934f83859b0ed8f35ad7546e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 26 Jan 2023 18:50:05 -0500 Subject: [PATCH] Add menu action to hide/show reblogs Closes #206 --- .../Sources/Pachyderm/Model/Account.swift | 6 ++++++ Tusker/Screens/Utilities/Previewing.swift | 21 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Packages/Pachyderm/Sources/Pachyderm/Model/Account.swift b/Packages/Pachyderm/Sources/Pachyderm/Model/Account.swift index 777ab19e..f18a7196 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Model/Account.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Model/Account.swift @@ -109,6 +109,12 @@ public final class Account: AccountProtocol, Decodable { return Request(method: .post, path: "/api/v1/accounts/\(accountID)/follow") } + public static func setShowReblogs(_ accountID: String, showReblogs: Bool) -> Request { + return Request(method: .post, path: "/api/v1/accounts/\(accountID)/follow", body: ParametersBody([ + "reblogs" => showReblogs + ])) + } + public static func unfollow(_ accountID: String) -> Request { return Request(method: .post, path: "/api/v1/accounts/\(accountID)/unfollow") } diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index 18050a9e..e385ad6d 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -97,8 +97,9 @@ extension MenuActionProvider { })) elementHandler([UIMenu(title: "Add to List", image: UIImage(systemName: "list.bullet"), children: listActions)]) })) - suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.blockAction(for: $0, mastodonController: $1) })) + suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.hideReblogsAction(for: $0, mastodonController: $1) })) suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.muteAction(for: $0, mastodonController: $1) })) + suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.blockAction(for: $0, mastodonController: $1) })) suppressSection.append(createAction(identifier: "report", title: "Report", systemImageName: "flag", handler: { [unowned self] _ in let view = ReportView(report: EditedReport(accountID: accountID), mastodonController: mastodonController) let host = UIHostingController(rootView: view) @@ -538,6 +539,24 @@ extension MenuActionProvider { } } + @MainActor + private func hideReblogsAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement { + 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 + let req = Account.setShowReblogs(relationship.accountID, showReblogs: !relationship.showingReblogs) + mastodonController.run(req) { response in + switch response { + case .failure(let error): + self?.handleError(error, title: "Error \(relationship.showingReblogs ? "Hiding" : "Showing") Reblogs") + case .success(let relationship, _): + mastodonController.persistentContainer.addOrUpdate(relationship: relationship) + self?.handleSuccess(title: relationship.showingReblogs ? "Reblogs Shown" : "Reblogs Hidden") + } + } + } + } + } private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? {