2018-09-23 16:01:05 +00:00
|
|
|
//
|
|
|
|
// XCBManager.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/23/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class XCBManager {
|
|
|
|
|
2018-09-26 01:41:12 +00:00
|
|
|
static var specs: [XCBRequestSpec] = [
|
2018-09-24 01:35:33 +00:00
|
|
|
// Statuses
|
2018-09-26 01:41:12 +00:00
|
|
|
XCBRequestSpec(type: .showStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: false, action: XCBActions.showStatus),
|
|
|
|
XCBRequestSpec(type: .getStatus, arguments: ["statusID": true, "statusURL": true, "html": true], canRunSilently: false, action: XCBActions.getStatus),
|
|
|
|
XCBRequestSpec(type: .postStatus, arguments: ["mentioning": true, "text": true], canRunSilently: true, action: XCBActions.postStatus),
|
|
|
|
XCBRequestSpec(type: .favoriteStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: true, action: XCBActions.favoriteStatus),
|
|
|
|
XCBRequestSpec(type: .reblogStatus, arguments: ["statusID": true, "statusURL": true], canRunSilently: true, action: XCBActions.reblogStatus),
|
2018-09-24 01:35:33 +00:00
|
|
|
// Accounts
|
2018-09-26 01:41:12 +00:00
|
|
|
XCBRequestSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount),
|
|
|
|
XCBRequestSpec(type: .getAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.getAccount),
|
|
|
|
XCBRequestSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser),
|
2019-09-15 22:12:49 +00:00
|
|
|
XCBRequestSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser),
|
|
|
|
// Search
|
|
|
|
XCBRequestSpec(type: .search, arguments: ["query": false], canRunSilently: false, action: XCBActions.search),
|
2018-09-23 16:01:05 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
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) }) {
|
2018-09-26 01:41:12 +00:00
|
|
|
let request = XCBRequest(spec: spec, components: components)
|
|
|
|
return spec.handle(request: request)
|
2018-09-23 16:01:05 +00:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-26 01:41:12 +00:00
|
|
|
static func createSession(type: XCBActionType, request: XCBRequest) -> XCBSession {
|
|
|
|
let session = XCBSession(type: type, request: request)
|
2018-09-23 16:01:05 +00:00
|
|
|
currentSession = session
|
|
|
|
return session
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|