41 lines
1.5 KiB
Swift
41 lines
1.5 KiB
Swift
//
|
|
// 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)
|
|
}
|
|
}
|
|
}
|