// // XCBActions.swift // Tusker // // Created by Shadowfacts on 9/23/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import UIKit struct XCBActions { // MARK: - Posts static func postStatus(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { let mentioning = url.arguments["mentioning"] let text = url.arguments["text"] if silent ?? false { var status = "" if let mentioning = mentioning { status += mentioning } if let text = text { status += text } let request = MastodonController.shared.client.createStatus(text: status, visibility: Preferences.shared.defaultPostVisibility) MastodonController.shared.client.run(request) { response in if case let .success(status, _) = response { session.complete(with: .success, additionalData: [ "statusURL": status.url?.absoluteString, "statusURI": status.uri ]) } else if case let .failure(error) = response { session.complete(with: .error, additionalData: [ "error": error.localizedDescription ]) } } } else { let vc = ComposeViewController.create(for: session, mentioning: mentioning, text: text) UIApplication.shared.keyWindow!.rootViewController!.present(vc, animated: true) } } // MARK: - Accounts static func getCurrentUser(_ url: XCallbackURL, _ session: XCBSession, _ silent: Bool?) { let account = MastodonController.shared.account! 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, ]) } }