Add reblog XCB action
This commit is contained in:
parent
4b2071af6a
commit
348a5ba241
|
@ -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
|
||||||
|
|
|
@ -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"
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue