diff --git a/Tusker/Info.plist b/Tusker/Info.plist
index f1dde381..46b8b212 100644
--- a/Tusker/Info.plist
+++ b/Tusker/Info.plist
@@ -6,6 +6,7 @@
$(PRODUCT_BUNDLE_IDENTIFIER).activity.show-timeline
$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-notifications
+ $(PRODUCT_BUNDLE_IDENTIFIER).activity.check-mentions
$(PRODUCT_BUNDLE_IDENTIFIER).activity.new-post
CFBundleDevelopmentRegion
diff --git a/Tusker/Screens/Main/MainTabBarViewController.swift b/Tusker/Screens/Main/MainTabBarViewController.swift
index 7b181fb3..47fa35cb 100644
--- a/Tusker/Screens/Main/MainTabBarViewController.swift
+++ b/Tusker/Screens/Main/MainTabBarViewController.swift
@@ -46,6 +46,16 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
navigationController.presentationController?.delegate = compose
present(navigationController, animated: true)
}
+}
+
+extension MainTabBarViewController {
+ enum Tab: Int {
+ case timelines
+ case notifications
+ case compose
+ case search
+ case myProfile
+ }
func select(tab: Tab) {
if tab == .compose {
@@ -62,15 +72,4 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
return viewControllers![tab.rawValue]
}
}
-
-}
-
-extension MainTabBarViewController {
- enum Tab: Int {
- case timelines
- case notifications
- case compose
- case search
- case myProfile
- }
}
diff --git a/Tusker/Screens/Notifications/NotificationsPageViewController.swift b/Tusker/Screens/Notifications/NotificationsPageViewController.swift
index e3df2dc3..c749ab65 100644
--- a/Tusker/Screens/Notifications/NotificationsPageViewController.swift
+++ b/Tusker/Screens/Notifications/NotificationsPageViewController.swift
@@ -17,9 +17,11 @@ class NotificationsPageViewController: SegmentedPageViewController {
init() {
let notifications = NotificationsTableViewController(allowedTypes: Pachyderm.Notification.Kind.allCases)
notifications.title = notificationsTitle
+ notifications.userActivity = UserActivityManager.checkNotificationsActivity()
let mentions = NotificationsTableViewController(allowedTypes: [.mention])
mentions.title = mentionsTitle
+ mentions.userActivity = UserActivityManager.checkMentionsActivity()
super.init(titles: [
notificationsTitle,
@@ -40,8 +42,12 @@ class NotificationsPageViewController: SegmentedPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
+ selectMode(Preferences.shared.defaultNotificationsMode)
+ }
+
+ func selectMode(_ mode: NotificationsMode) {
let index: Int
- switch Preferences.shared.defaultNotificationsMode {
+ switch mode {
case .allNotifications:
index = 0
case .mentionsOnly:
diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift
index 397c7ba1..fa3fd13a 100644
--- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift
+++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift
@@ -69,8 +69,6 @@ class NotificationsTableViewController: EnhancedTableViewController {
self.newer = pagination?.newer
self.older = pagination?.older
}
-
- userActivity = UserActivityManager.checkNotificationsActivity()
}
// MARK: - Table view data source
diff --git a/Tusker/Shortcuts/UserActivityManager.swift b/Tusker/Shortcuts/UserActivityManager.swift
index 079d3e73..e534d9cd 100644
--- a/Tusker/Shortcuts/UserActivityManager.swift
+++ b/Tusker/Shortcuts/UserActivityManager.swift
@@ -15,14 +15,14 @@ class UserActivityManager {
private static let encoder = PropertyListEncoder()
private static let decoder = PropertyListDecoder()
- private static func present(_ vc: UIViewController, animated: Bool = true) {
- UIApplication.shared.delegate?.window??.rootViewController?.present(vc, animated: animated)
- }
-
private static func getMainTabBarController() -> MainTabBarViewController {
return (UIApplication.shared.delegate! as! AppDelegate).window!.rootViewController as! MainTabBarViewController
}
+ private static func present(_ vc: UIViewController, animated: Bool = true) {
+ getMainTabBarController().present(vc, animated: animated)
+ }
+
// MARK: - New Post
static func newPostActivity(mentioning: Account? = nil) -> NSUserActivity {
let activity = NSUserActivity(type: .newPost)
@@ -49,13 +49,38 @@ class UserActivityManager {
static func checkNotificationsActivity() -> NSUserActivity {
let activity = NSUserActivity(type: .checkNotifications)
activity.isEligibleForPrediction = true
- activity.title = "Check Notifications"
- activity.suggestedInvocationPhrase = "Check my Tusker notifications"
+ activity.title = NSLocalizedString("Check Notifications", comment: "check notifications shortcut title")
+ activity.suggestedInvocationPhrase = NSLocalizedString("Check my Tusker notifications", comment: "check notifications shortcut invocation phrase")
return activity
}
static func handleCheckNotifications(activity: NSUserActivity) {
- getMainTabBarController().select(tab: .notifications)
+ let tabBarController = getMainTabBarController()
+ tabBarController.select(tab: .notifications)
+ if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
+ let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
+ navController.popToRootViewController(animated: false)
+ notificationsPageController.selectMode(.allNotifications)
+ }
+ }
+
+ // MARK: - Check Mentions
+ static func checkMentionsActivity() -> NSUserActivity {
+ let activity = NSUserActivity(type: .checkMentions)
+ activity.isEligibleForPrediction = true
+ activity.title = NSLocalizedString("Check Mentions", comment: "check mentions shortcut title")
+ activity.suggestedInvocationPhrase = NSLocalizedString("Check my mentions", comment: "check mentions shortcut invocation phrase")
+ return activity
+ }
+
+ static func handleCheckMentions(activity: NSUserActivity) {
+ let tabBarController = getMainTabBarController()
+ tabBarController.select(tab: .notifications)
+ if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
+ let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
+ navController.popToRootViewController(animated: false)
+ notificationsPageController.selectMode(.mentionsOnly)
+ }
}
// MARK: - Show Timeline
diff --git a/Tusker/Shortcuts/UserActivityType.swift b/Tusker/Shortcuts/UserActivityType.swift
index 0b83a10f..c3ecdea9 100644
--- a/Tusker/Shortcuts/UserActivityType.swift
+++ b/Tusker/Shortcuts/UserActivityType.swift
@@ -11,6 +11,7 @@ import Foundation
enum UserActivityType: String {
case newPost = "net.shadowfacts.Tusker.activity.new-post"
case checkNotifications = "net.shadowfacts.Tusker.activity.check-notifications"
+ case checkMentions = "net.shadowfacts.Tusker.activity.check-mentions"
case showTimeline = "net.shadowfacts.Tusker.activity.show-timeline"
}
@@ -21,6 +22,8 @@ extension UserActivityType {
return UserActivityManager.handleNewPost
case .checkNotifications:
return UserActivityManager.handleCheckNotifications
+ case .checkMentions:
+ return UserActivityManager.handleCheckMentions
case .showTimeline:
return UserActivityManager.handleShowTimeline
}