Tusker/Tusker/Shortcuts/UserActivityManager.swift

58 lines
2.0 KiB
Swift

//
// 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 var router: AppRouter = {
return (UIApplication.shared.delegate as! AppDelegate).router
}()
// 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
router.present(router.compose(mentioningAcct: mentioning), animated: true)
}
// 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 index = Preferences.shared.tabs[.notifications] ?? -1
guard index > 0 else { return }
let tabBarController = UIApplication.shared.keyWindow!.rootViewController! as! UITabBarController
tabBarController.selectedIndex = index
}
}