2018-10-20 14:54:59 +00:00
|
|
|
//
|
|
|
|
// UserActivityManager.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 10/19/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Pachyderm
|
|
|
|
|
|
|
|
class UserActivityManager {
|
|
|
|
|
|
|
|
// MARK: - Utils
|
2019-01-19 19:31:31 +00:00
|
|
|
private static func present(_ vc: UIViewController, animated: Bool = true) {
|
|
|
|
UIApplication.shared.delegate?.window??.rootViewController?.present(vc, animated: animated)
|
|
|
|
}
|
2018-10-20 14:54:59 +00:00
|
|
|
|
|
|
|
// MARK: - New Post
|
|
|
|
static func newPostActivity(mentioning: Account? = nil) -> NSUserActivity {
|
|
|
|
let activity = NSUserActivity(type: .newPost)
|
|
|
|
activity.isEligibleForPrediction = true
|
|
|
|
if let mentioning = mentioning {
|
|
|
|
activity.userInfo = ["mentioning": mentioning.acct]
|
|
|
|
activity.title = "Send a message to \(mentioning.realDisplayName)"
|
|
|
|
activity.suggestedInvocationPhrase = "Send a message to \(mentioning.realDisplayName)"
|
|
|
|
} else {
|
|
|
|
activity.userInfo = [:]
|
|
|
|
activity.title = "New Post"
|
|
|
|
activity.suggestedInvocationPhrase = "Post in Tusker"
|
|
|
|
}
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
static func handleNewPost(activity: NSUserActivity) {
|
|
|
|
// TODO: check not currently showing compose screen
|
|
|
|
let mentioning = activity.userInfo?["mentioning"] as? String
|
2019-07-29 16:15:33 +00:00
|
|
|
present(UINavigationController(rootViewController: ComposeViewController(mentioningAcct: mentioning)))
|
2018-10-20 14:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Check Notifications
|
|
|
|
static func checkNotificationsActivity() -> NSUserActivity {
|
|
|
|
let activity = NSUserActivity(type: .checkNotifications)
|
|
|
|
activity.isEligibleForPrediction = true
|
|
|
|
activity.title = "Check Notifications"
|
|
|
|
activity.suggestedInvocationPhrase = "Check my Tusker notifications"
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
static func handleCheckNotifications(activity: NSUserActivity) {
|
|
|
|
let tabBarController = UIApplication.shared.keyWindow!.rootViewController! as! UITabBarController
|
2019-07-29 16:15:33 +00:00
|
|
|
tabBarController.selectedIndex = 1
|
2018-10-20 14:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|