From b7c029210f13d04aab887bc342950cbaa3811737 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 25 Sep 2018 21:13:51 -0400 Subject: [PATCH] Add getStatus XCB action --- Documentation/X-Callback-URL.md | 3 ++- Tusker/XCallbackURL/XCBActionType.swift | 1 + Tusker/XCallbackURL/XCBActions.swift | 31 +++++++++++++++++++++++++ Tusker/XCallbackURL/XCBManager.swift | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Documentation/X-Callback-URL.md b/Documentation/X-Callback-URL.md index 6a12e09d..409eca36 100644 --- a/Documentation/X-Callback-URL.md +++ b/Documentation/X-Callback-URL.md @@ -187,8 +187,9 @@ Retrieves the given status details. One of `statusID` or `statusURL` must be pro | -------------------- | ------------------------------------------------------------ | -------- | | `url` (URL) | The URL of the status | Yes | | `uri` (string) | The URI of the status | No | +| `id` (string) | The instance-local ID of the status | | | `account` (string) | The [qualified username](#qualifiedusernames) of the account that posted (or reblogged if `reblog` is present) the status | No | -| `inReplyTo` (string) | The **instance-local** ID of the status | Yes | +| `inReplyTo` (string) | The instance-local ID of the status that this status is a reply to | Yes | | `posted` (date) | The date the status was posted | No | | `content` (string) | The content of the status (HTML if the `html` parameter was true, plain-text otherwise) | No | | `reblog` (string) | The **instance-local** ID of the status that this is a reblog of. If not present, this status was not a reblog. | Yes | diff --git a/Tusker/XCallbackURL/XCBActionType.swift b/Tusker/XCallbackURL/XCBActionType.swift index 56f23c62..9e0d49f4 100644 --- a/Tusker/XCallbackURL/XCBActionType.swift +++ b/Tusker/XCallbackURL/XCBActionType.swift @@ -12,6 +12,7 @@ enum XCBActionType: String { // Statuses case showStatus case postStatus + case getStatus case favoriteStatus case reblogStatus // Accounts diff --git a/Tusker/XCallbackURL/XCBActions.swift b/Tusker/XCallbackURL/XCBActions.swift index 2bed567b..e8cacd17 100644 --- a/Tusker/XCallbackURL/XCBActions.swift +++ b/Tusker/XCallbackURL/XCBActions.swift @@ -8,6 +8,7 @@ import UIKit import Pachyderm +import SwiftSoup struct XCBActions { @@ -144,6 +145,36 @@ struct XCBActions { } } + static func getStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { + getStatus(from: url, session: session) { (status) in + let html = Bool(url.arguments["html"] ?? "false") ?? false + let content: String + if html { + content = status.content + } else { + do { + let doc = try SwiftSoup.parse(status.content) + content = try doc.body()!.text() + } catch { + session.complete(with: .error, additionalData: [ + "error": error.localizedDescription + ]) + return + } + } + session.complete(with: .success, additionalData: [ + "url": status.url?.absoluteString, + "uri": status.uri, + "id": status.id, + "account": status.account.acct, + "inReplyTo": status.inReplyToID, + "posted": status.createdAt.timeIntervalSince1970.description, + "content": content, + "reblog": status.reblog?.id + ]) + } + } + static func favoriteStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { statusAction(request: Status.favourite, alertTitle: "Favorite status?", url, session, silent) } diff --git a/Tusker/XCallbackURL/XCBManager.swift b/Tusker/XCallbackURL/XCBManager.swift index 22db0e56..f48e654b 100644 --- a/Tusker/XCallbackURL/XCBManager.swift +++ b/Tusker/XCallbackURL/XCBManager.swift @@ -13,6 +13,7 @@ class XCBManager { static var specs: [XCallbackURLSpec] = [ // Statuses XCallbackURLSpec(type: .showStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: false, action: XCBActions.showStatus), + XCallbackURLSpec(type: .getStatus, arguments: ["statusID": true, "statusURL": true, "html": true], canRunSilently: false, action: XCBActions.getStatus), 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),