// // XCBManager.swift // Tusker // // Created by Shadowfacts on 9/23/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import UIKit 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), // Accounts XCallbackURLSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount), XCallbackURLSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser), XCallbackURLSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser) ] static var currentSession: XCBSession? static func handle(url: URL) -> Bool { guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { return false } if let spec = specs.first(where: { $0.matches(components) }) { let xcbURL = XCallbackURL(spec: spec, components: components) return spec.handle(url: xcbURL) } return false } static func createSession(type: XCBActionType, url: XCallbackURL) -> XCBSession { let session = XCBSession(type: type, success: url.success, error: url.error, cancel: url.cancel) currentSession = session return session } }