Browse Source

Add getStatus XCB action

pixelfed
Shadowfacts 3 years ago
parent
commit
e082076a23
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 3
      Documentation/X-Callback-URL.md
  2. 1
      Tusker/XCallbackURL/XCBActionType.swift
  3. 31
      Tusker/XCallbackURL/XCBActions.swift
  4. 1
      Tusker/XCallbackURL/XCBManager.swift

3
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 |

1
Tusker/XCallbackURL/XCBActionType.swift

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

31
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)
}

1
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),

Loading…
Cancel
Save