Skip to content

Commit a971424

Browse files
committed
UserActivityService: make sure roomID exists
Signed-off-by: Finn Behrens <[email protected]>
1 parent 448ed1a commit a971424

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

Riot/Managers/Activities/UserActivityService.swift

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
//
1616

1717
import Foundation
18-
import CoreSpotlight
1918
import MatrixSDK
2019

2120
@objcMembers
2221
class UserActivityService: NSObject {
2322

2423
// MARK: - Properties
2524

26-
#warning("This is initialised lazily so currently only observes left rooms if RoomViewController has been presented.")
2725
static let shared = UserActivityService()
2826

2927
// MARK: - Setup
@@ -38,50 +36,35 @@ class UserActivityService: NSObject {
3836
// MARK: - Public
3937

4038
func update(_ userActivity: NSUserActivity, from room: MXRoom) {
39+
guard let roomId = room.roomId else {
40+
return
41+
}
4142
userActivity.title = room.summary.displayname
4243

4344
userActivity.requiredUserInfoKeys = [ UserActivityField.room.rawValue ]
4445
var userInfo = [String: Any]()
45-
userInfo[UserActivityField.room.rawValue] = room.roomId
46+
userInfo[UserActivityField.room.rawValue] = roomId
4647
if room.isDirect {
4748
userInfo[UserActivityField.user.rawValue] = room.directUserId
4849
}
4950
userActivity.userInfo = userInfo
5051

5152
// TODO: if we add more userActivities, a `org.matrix.room` prefix should probably be added
52-
userActivity.persistentIdentifier = room.roomId
53+
userActivity.persistentIdentifier = roomId
5354

5455
userActivity.isEligibleForHandoff = true
5556
userActivity.isEligibleForSearch = true
5657
userActivity.isEligibleForPrediction = true
5758

58-
var contentAttributes: CSSearchableItemAttributeSet
59-
if #available(iOS 14.0, *) {
60-
contentAttributes = CSSearchableItemAttributeSet(contentType: UTType.item)
61-
} else {
62-
contentAttributes = CSSearchableItemAttributeSet(itemContentType: "public.item")
63-
}
64-
65-
contentAttributes.title = room.summary.displayname
66-
contentAttributes.displayName = room.summary.displayname
67-
contentAttributes.contentDescription = room.summary.lastMessage.text
68-
// TODO: contentAttributes.thumbnailURL
69-
contentAttributes.domainIdentifier = room.roomId
70-
contentAttributes.relatedUniqueIdentifier = room.summary.lastMessage.eventId
71-
// TODO: contentAttributes.weakRelatedUniqueIdentifier (is this needed? does it break anything else?)
72-
contentAttributes.instantMessageAddresses = [ room.roomId ]
7359

74-
userActivity.contentAttributeSet = contentAttributes
7560
}
7661

7762
func didLeaveRoom(_ notification: Notification) {
7863
guard let roomId = notification.userInfo?[kMXSessionNotificationRoomIdKey] as? String else { return }
7964
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: [roomId], completionHandler: { })
80-
CSSearchableIndex.default().deleteSearchableItems(withDomainIdentifiers: [roomId], completionHandler: nil)
8165
}
8266

8367
func didLogOut(_ notification: Notification) {
8468
NSUserActivity.deleteAllSavedUserActivities(completionHandler: { })
85-
CSSearchableIndex.default().deleteAllSearchableItems(completionHandler: nil)
8669
}
8770
}

Riot/Modules/Application/AppCoordinator.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ final class AppCoordinator: NSObject, AppCoordinatorType {
7979
func start() {
8080
self.setupLogger()
8181
self.setupTheme()
82+
83+
// Make sure the UserActivityService is loaded
84+
let _ = UserActivityService.shared
8285

8386
// Setup navigation router store
8487
_ = NavigationRouterStore.shared

Riot/Modules/Application/LegacyAppDelegate.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,11 @@ - (void)selectMatrixAccount:(void (^)(MXKAccount *selectedAccount))onSelection
27902790
#pragma mark - Matrix Rooms handling
27912791

27922792
- (void)navigateToRoomById:(NSString *)roomId
2793+
{
2794+
[self navigateToRoomById:roomId andEventId:nil];
2795+
}
2796+
2797+
- (void)navigateToRoomById:(NSString *)roomId andEventId:(NSString *)eventId
27932798
{
27942799
if (roomId.length)
27952800
{
@@ -2823,7 +2828,7 @@ - (void)navigateToRoomById:(NSString *)roomId
28232828
{
28242829
MXLogDebug(@"[AppDelegate][Push] navigateToRoomById: open the roomViewController %@", roomId);
28252830

2826-
[self showRoom:roomId andEventId:nil withMatrixSession:dedicatedAccount.mxSession];
2831+
[self showRoom:roomId andEventId:eventId withMatrixSession:dedicatedAccount.mxSession];
28272832
}
28282833
else
28292834
{

0 commit comments

Comments
 (0)