Add getStatus XCB action

This commit is contained in:
Shadowfacts 2018-09-25 21:13:51 -04:00
parent b537321057
commit 51c178ec4d
4 changed files with 35 additions and 1 deletions

View File

@ -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 | | `url` (URL) | The URL of the status | Yes |
| `uri` (string) | The URI of the status | No | | `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 | | `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 | | `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 | | `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 | | `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 |

View File

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

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
import Pachyderm import Pachyderm
import SwiftSoup
struct XCBActions { 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?) { static func favoriteStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) {
statusAction(request: Status.favourite, alertTitle: "Favorite status?", url, session, silent) statusAction(request: Status.favourite, alertTitle: "Favorite status?", url, session, silent)
} }

View File

@ -13,6 +13,7 @@ class XCBManager {
static var specs: [XCallbackURLSpec] = [ static var specs: [XCallbackURLSpec] = [
// Statuses // Statuses
XCallbackURLSpec(type: .showStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: false, action: XCBActions.showStatus), 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: .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), XCallbackURLSpec(type: .reblogStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: true, action: XCBActions.reblogStatus),