From 31968cad98d221aa1b8e565990b462aa919b511f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 24 Sep 2018 19:56:27 -0400 Subject: [PATCH] Add reblog XCB action --- Tusker/XCallbackURL/XCBActionType.swift | 1 + Tusker/XCallbackURL/XCBActions.swift | 15 +++++++++++---- Tusker/XCallbackURL/XCBManager.swift | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Tusker/XCallbackURL/XCBActionType.swift b/Tusker/XCallbackURL/XCBActionType.swift index 60a1cad1..d05f7252 100644 --- a/Tusker/XCallbackURL/XCBActionType.swift +++ b/Tusker/XCallbackURL/XCBActionType.swift @@ -12,6 +12,7 @@ enum XCBActionType: String { // Statuses case postStatus case favoriteStatus + case reblogStatus // Accounts case getCurrentUser case followUser diff --git a/Tusker/XCallbackURL/XCBActions.swift b/Tusker/XCallbackURL/XCBActions.swift index 7b51a400..c7572101 100644 --- a/Tusker/XCallbackURL/XCBActions.swift +++ b/Tusker/XCallbackURL/XCBActions.swift @@ -51,9 +51,16 @@ struct XCBActions { } static func favoriteStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { + statusAction(request: Status.favourite, alertTitle: "Favorite status?", url, session, silent) + } + + static func reblogStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { + statusAction(request: Status.reblog, alertTitle: "Reblog status?", url, session, silent) + } + + static func statusAction(request: @escaping (Status) -> Request, alertTitle: String, _ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { func performAction(status: Status, completion: ((Status) -> Void)?) { - let request = Status.favourite(status) - MastodonController.shared.client.run(request) { (response) in + MastodonController.shared.client.run(request(status)) { (response) in if case let .success(status, _) = response { MastodonCache.add(status: status) completion?(status) @@ -77,7 +84,7 @@ struct XCBActions { DispatchQueue.main.async { presentNav(vc, animated: true) } - let alertController = UIAlertController(title: "Favorite status?", message: nil, preferredStyle: .alert) + let alertController = UIAlertController(title: alertTitle, message: nil, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (_) in performAction(status: status, completion: { (status) in DispatchQueue.main.async { @@ -118,7 +125,7 @@ struct XCBActions { } } else { session.complete(with: .error, additionalData: [ - "error": "No status provided. Specify either instance-local statusID or remote statusURL/statusURI" + "error": "No status provided. Specify either instance-local statusID or remote statusURL" ]) } } diff --git a/Tusker/XCallbackURL/XCBManager.swift b/Tusker/XCallbackURL/XCBManager.swift index 7ae728ca..eae30361 100644 --- a/Tusker/XCallbackURL/XCBManager.swift +++ b/Tusker/XCallbackURL/XCBManager.swift @@ -14,6 +14,7 @@ class XCBManager { // Statuses XCallbackURLSpec(type: .postStatus, arguments: ["mentioning": true, "text": true], canRunSilently: true, action: XCBActions.postStatus), XCallbackURLSpec(type: .favoriteStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: true, action: XCBActions.favoriteStatus), + XCallbackURLSpec(type: .reblogStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: true, action: XCBActions.reblogStatus), // Accounts XCallbackURLSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser), XCallbackURLSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser)