From 7161861d364bd6ecf7762bd0b9f1deb58f3c32b2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 18 Sep 2022 00:26:37 -0400 Subject: [PATCH] Add API param for reblog visibility --- Pachyderm/Sources/Pachyderm/Model/Status.swift | 9 +++++++-- Tusker/Screens/Utilities/Previewing.swift | 7 ++++++- Tusker/Views/Status/BaseStatusTableViewCell.swift | 13 +++++++++---- Tusker/XCallbackURL/XCBActions.swift | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Pachyderm/Sources/Pachyderm/Model/Status.swift b/Pachyderm/Sources/Pachyderm/Model/Status.swift index a5ee7c95..b488b068 100644 --- a/Pachyderm/Sources/Pachyderm/Model/Status.swift +++ b/Pachyderm/Sources/Pachyderm/Model/Status.swift @@ -67,8 +67,13 @@ public final class Status: StatusProtocol, Decodable { return Request(method: .delete, path: "/api/v1/statuses/\(status.id)") } - public static func reblog(_ statusID: String) -> Request { - return Request(method: .post, path: "/api/v1/statuses/\(statusID)/reblog") + public static func reblog(_ statusID: String, visibility: Visibility? = nil) -> Request { + var params: [Parameter] = [] + if let visibility { + assert([.public, .unlisted, .private].contains(visibility)) + params.append("visibility" => visibility.rawValue) + } + return Request(method: .post, path: "/api/v1/statuses/\(statusID)/reblog", queryParameters: params) } public static func unreblog(_ statusID: String) -> Request { diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index c9054b86..778588cc 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -198,7 +198,12 @@ extension MenuActionProvider { } toggleableSection.insert(createAction(identifier: "reblog", title: reblogged ? "Unreblog" : "Reblog", image: reblogImage, handler: { [weak self] _ in guard let self = self else { return } - let request = (reblogged ? Status.reblog : Status.unreblog)(status.id) + let request: Request + if reblogged { + request = Status.reblog(status.id) + } else { + request = Status.unreblog(status.id) + } self.mastodonController?.run(request, completion: { response in switch response { case .success(let status, _): diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 65a4410d..04cc21c3 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -416,24 +416,29 @@ class BaseStatusTableViewCell: UITableViewCell { let config = CustomAlertController.Configuration(title: "Are you sure you want to reblog this post?", content: preview, actions: [ CustomAlertController.Action(title: "Cancel", style: .cancel, handler: nil), CustomAlertController.Action(title: "Reblog", style: .default, handler: { [unowned self] in - self.toggleReblogInternal() + self.toggleReblogInternal(visibility: nil) }), ]) let alert = CustomAlertController(config: config) delegate?.present(alert, animated: true) } else { - toggleReblogInternal() + toggleReblogInternal(visibility: nil) } } - private func toggleReblogInternal() { + private func toggleReblogInternal(visibility: Status.Visibility?) { guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") } let oldValue = reblogged reblogged = !reblogged let realStatus = status.reblog ?? status - let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus.id) + let request: Request + if reblogged { + request = Status.reblog(realStatus.id, visibility: visibility) + } else { + request = Status.unreblog(realStatus.id) + } mastodonController.run(request) { response in DispatchQueue.main.async { if case let .success(newStatus, _) = response { diff --git a/Tusker/XCallbackURL/XCBActions.swift b/Tusker/XCallbackURL/XCBActions.swift index 5d44f618..56d97114 100644 --- a/Tusker/XCallbackURL/XCBActions.swift +++ b/Tusker/XCallbackURL/XCBActions.swift @@ -202,7 +202,7 @@ struct XCBActions { } static func reblogStatus(_ request: XCBRequest, _ session: XCBSession, _ silent: Bool?) { - statusAction(request: Status.reblog, alertTitle: "Reblog status?", request, session, silent) + statusAction(request: { Status.reblog($0) }, alertTitle: "Reblog status?", request, session, silent) } static func statusAction(request: @escaping (String) -> Request, alertTitle: String, _ url: XCBRequest, _ session: XCBSession, _ silent: Bool?) {