1515//
1616
1717import Foundation
18- import CoreSpotlight
1918import MatrixSDK
2019
2120@objcMembers
2221class 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}
0 commit comments