Add reblog XCB action

This commit is contained in:
Shadowfacts 2018-09-24 19:56:27 -04:00
parent 4b2071af6a
commit 348a5ba241
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 13 additions and 4 deletions

View File

@ -12,6 +12,7 @@ enum XCBActionType: String {
// Statuses // Statuses
case postStatus case postStatus
case favoriteStatus case favoriteStatus
case reblogStatus
// Accounts // Accounts
case getCurrentUser case getCurrentUser
case followUser case followUser

View File

@ -51,9 +51,16 @@ struct XCBActions {
} }
static func favoriteStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { 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<Status>, alertTitle: String, _ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) {
func performAction(status: Status, completion: ((Status) -> Void)?) { func performAction(status: Status, completion: ((Status) -> Void)?) {
let request = Status.favourite(status) MastodonController.shared.client.run(request(status)) { (response) in
MastodonController.shared.client.run(request) { (response) in
if case let .success(status, _) = response { if case let .success(status, _) = response {
MastodonCache.add(status: status) MastodonCache.add(status: status)
completion?(status) completion?(status)
@ -77,7 +84,7 @@ struct XCBActions {
DispatchQueue.main.async { DispatchQueue.main.async {
presentNav(vc, animated: true) 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 alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (_) in
performAction(status: status, completion: { (status) in performAction(status: status, completion: { (status) in
DispatchQueue.main.async { DispatchQueue.main.async {
@ -118,7 +125,7 @@ struct XCBActions {
} }
} else { } else {
session.complete(with: .error, additionalData: [ 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"
]) ])
} }
} }

View File

@ -14,6 +14,7 @@ class XCBManager {
// Statuses // Statuses
XCallbackURLSpec(type: .postStatus, arguments: ["mentioning": true, "text": true], canRunSilently: true, action: XCBActions.postStatus), 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: .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 // Accounts
XCallbackURLSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser), XCallbackURLSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser),
XCallbackURLSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser) XCallbackURLSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser)