// // UserActivityManager.swift // Tusker // // Created by Shadowfacts on 10/19/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import UIKit import Pachyderm class UserActivityManager { // MARK: - Utils private static func present(_ vc: UIViewController, animated: Bool = true) { UIApplication.shared.delegate?.window??.rootViewController?.present(vc, animated: animated) } // 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 present(ComposeViewController(mentioningAcct: mentioning)) } // 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 tabBarController.selectedIndex = 2 } }