Add reblog XCB action

This commit is contained in:
Shadowfacts 2018-09-24 19:56:27 -04:00
parent 121d36aa73
commit 93e0e488d5
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 13 additions and 4 deletions

View File

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

View File

@ -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<Status>, 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"
])
}
}

View File

@ -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)