From d74be9d81d6137f2e2b3d55e9f0519842d7bbd7c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 25 Feb 2023 15:00:55 -0500 Subject: [PATCH] Add handoff to various user activities --- .../Conversation/ConversationViewController.swift | 4 ++++ Tusker/Screens/Profile/MyProfileViewController.swift | 4 +++- Tusker/Screens/Profile/ProfileViewController.swift | 12 ++++++++---- Tusker/Screens/Timeline/TimelineViewController.swift | 5 ++++- Tusker/Shortcuts/UserActivityManager.swift | 4 ++++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Tusker/Screens/Conversation/ConversationViewController.swift b/Tusker/Screens/Conversation/ConversationViewController.swift index 21babeaa..3ccc51a7 100644 --- a/Tusker/Screens/Conversation/ConversationViewController.swift +++ b/Tusker/Screens/Conversation/ConversationViewController.swift @@ -227,6 +227,10 @@ class ConversationViewController: UIViewController { } private func mainStatusLoaded(_ mainStatus: StatusMO) { + if let accountID = mastodonController.accountInfo?.id { + userActivity = UserActivityManager.showConversationActivity(mainStatusID: mainStatus.id, accountID: accountID) + } + let vc = ConversationCollectionViewController(for: mainStatus.id, state: mainStatusState, conversationViewController: self) vc.statusIDToScrollToOnLoad = statusIDToScrollToOnLoad ?? mainStatus.id vc.showStatusesAutomatically = showStatusesAutomatically diff --git a/Tusker/Screens/Profile/MyProfileViewController.swift b/Tusker/Screens/Profile/MyProfileViewController.swift index 1ed607ec..a859779f 100644 --- a/Tusker/Screens/Profile/MyProfileViewController.swift +++ b/Tusker/Screens/Profile/MyProfileViewController.swift @@ -38,7 +38,9 @@ class MyProfileViewController: ProfileViewController { navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Preferences", style: .plain, target: self, action: #selector(preferencesPressed)) NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil) - + } + + override func updateUserActivity() { userActivity = UserActivityManager.myProfileActivity(accountID: mastodonController.accountInfo!.id) } diff --git a/Tusker/Screens/Profile/ProfileViewController.swift b/Tusker/Screens/Profile/ProfileViewController.swift index 8a34d653..4872595b 100644 --- a/Tusker/Screens/Profile/ProfileViewController.swift +++ b/Tusker/Screens/Profile/ProfileViewController.swift @@ -109,6 +109,13 @@ class ProfileViewController: UIViewController, StateRestorableViewController { } } + func updateUserActivity() { + if let accountID, + let currentAccountID = mastodonController.accountInfo?.id { + userActivity = UserActivityManager.showProfileActivity(id: accountID, accountID: currentAccountID) + } + } + private func loadAccount() async { guard let accountID else { return @@ -136,10 +143,7 @@ class ProfileViewController: UIViewController, StateRestorableViewController { } private func updateAccountUI(account: AccountMO) { - if let currentAccountID = mastodonController.accountInfo?.id { - userActivity = UserActivityManager.showProfileActivity(id: account.id, accountID: currentAccountID) - } - + updateUserActivity() navigationItem.title = account.displayNameWithoutCustomEmoji } diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 3ce956e8..ea5fd0bf 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -44,7 +44,6 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro private var cancellables = Set() private var contentOffsetObservation: NSKeyValueObservation? - private var activityToRestore: NSUserActivity? // the last time this VC disappeared or the scene was backgrounded while it was active, used to decide if we want to check for present when reappearing private var disappearedAt: Date? @@ -69,6 +68,10 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro self.navigationItem.title = timeline.title addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Timeline")) + + if let accountID = mastodonController.accountInfo?.id { + self.userActivity = UserActivityManager.showTimelineActivity(timeline: timeline, accountID: accountID) + } } required init?(coder: NSCoder) { diff --git a/Tusker/Shortcuts/UserActivityManager.swift b/Tusker/Shortcuts/UserActivityManager.swift index 5c2f8d46..6f4ed91e 100644 --- a/Tusker/Shortcuts/UserActivityManager.swift +++ b/Tusker/Shortcuts/UserActivityManager.swift @@ -124,6 +124,7 @@ class UserActivityManager { static func checkNotificationsActivity(mode: NotificationsMode = .allNotifications, accountID: String) -> NSUserActivity { let activity = NSUserActivity(type: .checkNotifications, accountID: accountID) activity.isEligibleForPrediction = true + activity.isEligibleForHandoff = true activity.addUserInfoEntries(from: [ "notificationsMode": mode.rawValue ]) @@ -160,6 +161,7 @@ class UserActivityManager { let activity = NSUserActivity(type: .showTimeline, accountID: accountID) activity.isEligibleForPrediction = true + activity.isEligibleForHandoff = true activity.addUserInfoEntries(from: [ "timelineData": timelineData, ]) @@ -221,6 +223,7 @@ class UserActivityManager { "mainStatusID": mainStatusID, ]) activity.isEligibleForPrediction = isEligibleForPrediction + activity.isEligibleForHandoff = true return activity } @@ -298,6 +301,7 @@ class UserActivityManager { static func myProfileActivity(accountID: String) -> NSUserActivity { let activity = NSUserActivity(type: .myProfile, accountID: accountID) activity.isEligibleForPrediction = true + activity.isEligibleForHandoff = true activity.title = NSLocalizedString("My Profile", comment: "my profile shortcut title") activity.suggestedInvocationPhrase = NSLocalizedString("Show my Mastodon profile", comment: "my profile shortuct invocation phrase") return activity