From 0bfc96fe3812a9a5c76756a44bda2f16c6269f46 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 25 Sep 2018 21:20:34 -0400 Subject: [PATCH] Add getAccount XCB action --- Tusker/XCallbackURL/XCBActionType.swift | 1 + Tusker/XCallbackURL/XCBActions.swift | 17 ++++++++++++++++- Tusker/XCallbackURL/XCBManager.swift | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Tusker/XCallbackURL/XCBActionType.swift b/Tusker/XCallbackURL/XCBActionType.swift index 9e0d49f438..d3eeb4cf98 100644 --- a/Tusker/XCallbackURL/XCBActionType.swift +++ b/Tusker/XCallbackURL/XCBActionType.swift @@ -17,6 +17,7 @@ enum XCBActionType: String { case reblogStatus // Accounts case showAccount + case getAccount case getCurrentUser case followUser diff --git a/Tusker/XCallbackURL/XCBActions.swift b/Tusker/XCallbackURL/XCBActions.swift index e8cacd1765..7b39e3fb9b 100644 --- a/Tusker/XCallbackURL/XCBActions.swift +++ b/Tusker/XCallbackURL/XCBActions.swift @@ -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?) { let account = MastodonController.shared.account! session.complete(with: .success, additionalData: [ @@ -249,7 +264,7 @@ struct XCBActions { "following": account.followingCount.description, "url": account.url.absoluteString, "avatarURL": account.avatar.absoluteString, - "headerURL": account.header.absoluteString, + "headerURL": account.header.absoluteString ]) } diff --git a/Tusker/XCallbackURL/XCBManager.swift b/Tusker/XCallbackURL/XCBManager.swift index f48e654b84..9f4646ca0a 100644 --- a/Tusker/XCallbackURL/XCBManager.swift +++ b/Tusker/XCallbackURL/XCBManager.swift @@ -19,6 +19,7 @@ class XCBManager { XCallbackURLSpec(type: .reblogStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: true, action: XCBActions.reblogStatus), // Accounts 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: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser) ]