Add getAccount XCB action

This commit is contained in:
Shadowfacts 2018-09-25 21:20:34 -04:00
parent 51c178ec4d
commit d480c1927a
3 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,7 @@ enum XCBActionType: String {
case reblogStatus case reblogStatus
// Accounts // Accounts
case showAccount case showAccount
case getAccount
case getCurrentUser case getCurrentUser
case followUser case followUser

View File

@ -239,6 +239,21 @@ struct XCBActions {
} }
} }
static func getAccount(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) {
getAccount(from: url, session: session) { (account) in
session.complete(with: .success, additionalData: [
"username": account.acct,
"displayName": account.displayName,
"locked": account.locked.description,
"followers": account.followersCount.description,
"following": account.followingCount.description,
"url": account.url.absoluteString,
"avatarURL": account.avatar.absoluteString,
"headerURL": account.header.absoluteString
])
}
}
static func getCurrentUser(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { static func getCurrentUser(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) {
let account = MastodonController.shared.account! let account = MastodonController.shared.account!
session.complete(with: .success, additionalData: [ session.complete(with: .success, additionalData: [
@ -249,7 +264,7 @@ struct XCBActions {
"following": account.followingCount.description, "following": account.followingCount.description,
"url": account.url.absoluteString, "url": account.url.absoluteString,
"avatarURL": account.avatar.absoluteString, "avatarURL": account.avatar.absoluteString,
"headerURL": account.header.absoluteString, "headerURL": account.header.absoluteString
]) ])
} }

View File

@ -19,6 +19,7 @@ class XCBManager {
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),
// Accounts // Accounts
XCallbackURLSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount), XCallbackURLSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount),
XCallbackURLSpec(type: .getAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.getAccount),
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)
] ]