Add getStatus XCB action
This commit is contained in:
parent
a8539e33b9
commit
b7c029210f
|
@ -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 |
|
||||
|
|
|
@ -12,6 +12,7 @@ enum XCBActionType: String {
|
|||
// Statuses
|
||||
case showStatus
|
||||
case postStatus
|
||||
case getStatus
|
||||
case favoriteStatus
|
||||
case reblogStatus
|
||||
// Accounts
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue