Skip to content

Commit 3086234

Browse files
committed
Add NSUserActivity to rooms to appear in spotlight search
Signed-off-by: Finn Behrens <[email protected]>
1 parent 756b14d commit 3086234

File tree

6 files changed

+125
-1
lines changed

6 files changed

+125
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Copyright 2021 New Vector Ltd
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#ifndef UserActivities_h
18+
#define UserActivities_h
19+
20+
#import <Foundation/Foundation.h>
21+
22+
/**
23+
NSUserActivity types for rooms
24+
*/
25+
FOUNDATION_EXPORT NSString *const kUserActivityTypeMatrixRoom;
26+
27+
/**
28+
UserInfo field for the room id
29+
*/
30+
FOUNDATION_EXPORT NSString *const kUserActivityInfoRoomId;
31+
32+
/**
33+
UserInfo field for the user id
34+
*/
35+
FOUNDATION_EXPORT NSString *const kUserActivityInfoUserId;
36+
37+
#endif /* UserActivities_h */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Copyright 2021 New Vector Ltd
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import "UserActivities.h"
18+
19+
NSString *const kUserActivityTypeMatrixRoom = @"org.matrix.room";
20+
NSString *const kUserActivityInfoRoomId = @"roomID";
21+
NSString *const kUserActivityInfoUserId = @"userID";

Riot/Modules/Application/LegacyAppDelegate.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#import "Riot-Swift.h"
5959
#import "PushNotificationService.h"
6060

61+
#import "UserActivities.h"
62+
6163
//#define MX_CALL_STACK_OPENWEBRTC
6264
#ifdef MX_CALL_STACK_OPENWEBRTC
6365
#import <MatrixOpenWebRTCWrapper/MatrixOpenWebRTCWrapper.h>
@@ -749,13 +751,22 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct
749751
{
750752
continueUserActivity = [self handleUniversalLink:userActivity];
751753
}
754+
else if ([userActivity.activityType isEqualToString:kUserActivityTypeMatrixRoom])
755+
{
756+
NSString *roomID = userActivity.userInfo[kUserActivityInfoRoomId];
757+
if (!roomID)
758+
return continueUserActivity;
759+
760+
[self navigateToRoomById:roomID];
761+
continueUserActivity = YES;
762+
}
752763
else if ([userActivity.activityType isEqualToString:INStartAudioCallIntentIdentifier] ||
753764
[userActivity.activityType isEqualToString:INStartVideoCallIntentIdentifier])
754765
{
755766
INInteraction *interaction = userActivity.interaction;
756767

757768
// roomID provided by Siri intent
758-
NSString *roomID = userActivity.userInfo[@"roomID"];
769+
NSString *roomID = userActivity.userInfo[kUserActivityInfoRoomId];
759770

760771
// We've launched from calls history list
761772
if (!roomID)

Riot/Modules/Room/RoomViewController.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
limitations under the License.
1717
*/
1818

19+
@import CoreSpotlight;
20+
1921
#import "RoomViewController.h"
2022

2123
#import "RoomDataSource.h"
@@ -128,6 +130,8 @@
128130

129131
#import "MXSDKOptions.h"
130132

133+
#import "UserActivities.h"
134+
131135
#import "Riot-Swift.h"
132136

133137
NSNotificationName const RoomCallTileTappedNotification = @"RoomCallTileTappedNotification";
@@ -590,6 +594,8 @@ - (void)viewWillAppear:(BOOL)animated
590594
notificationTaskProfile = [MXSDKOptions.sharedInstance.profiler startMeasuringTaskWithName:AnalyticsNoficationsTimeToDisplayContent
591595
category:AnalyticsNoficationsCategory];
592596
}
597+
598+
[self becomeCurrentActivity];
593599
}
594600

595601
- (void)viewWillDisappear:(BOOL)animated
@@ -1995,6 +2001,50 @@ - (void)setupActions {
19952001
roomInputView.actionsBar.actionItems = actionItems;
19962002
}
19972003

2004+
- (void)becomeCurrentActivity
2005+
{
2006+
if (!self.userActivity) {
2007+
self.userActivity = [[NSUserActivity alloc] initWithActivityType:kUserActivityTypeMatrixRoom];
2008+
}
2009+
2010+
self.userActivity.title = self.roomDataSource.room.summary.displayname;
2011+
self.userActivity.requiredUserInfoKeys = [[NSSet alloc] initWithObjects:kUserActivityInfoRoomId, nil];
2012+
2013+
// user info
2014+
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
2015+
[userInfo setObject:self.roomDataSource.roomId forKey:kUserActivityInfoRoomId];
2016+
if ([self.roomDataSource.room isDirect]) {
2017+
[userInfo setObject:self.roomDataSource.room.directUserId forKey:kUserActivityInfoUserId];
2018+
}
2019+
self.userActivity.userInfo = userInfo;
2020+
2021+
// TODO: add a NSUserActivityDelegate to save the current text in the userinfo of the activity
2022+
// self.userActivity.delegate = self;
2023+
// self.userActivity.needsSave = true;
2024+
self.userActivity.persistentIdentifier = self.roomDataSource.roomId;
2025+
2026+
self.userActivity.eligibleForHandoff = true;
2027+
self.userActivity.eligibleForSearch = true;
2028+
self.userActivity.eligibleForPrediction = true;
2029+
2030+
CSSearchableItemAttributeSet *contentAttribute;
2031+
if (@available(iOS 14.0, *)) {
2032+
contentAttribute = [[CSSearchableItemAttributeSet alloc] initWithContentType:UTTypeItem];
2033+
} else {
2034+
contentAttribute = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:@"public.item"];
2035+
}
2036+
2037+
contentAttribute.title = self.roomDataSource.room.summary.displayname;
2038+
contentAttribute.displayName = self.roomDataSource.room.summary.displayname;
2039+
contentAttribute.contentDescription = self.roomDataSource.room.summary.lastMessage.text;
2040+
2041+
// TODO: contentAttribute.thumbnailURL =
2042+
// TODO: accountHandles of everyone in the room
2043+
contentAttribute.instantMessageAddresses = [[NSArray alloc] initWithObjects:self.roomDataSource.roomId, nil];
2044+
2045+
self.userActivity.contentAttributeSet = contentAttribute;
2046+
}
2047+
19982048
- (void)roomInputToolbarViewPresentStickerPicker
19992049
{
20002050
// Search for the sticker picker widget in the user account

Riot/SupportingFiles/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
<string>The photo library is used to send photos and videos.</string>
6666
<key>NSSiriUsageDescription</key>
6767
<string>Siri is used to perform calls even from the lock screen.</string>
68+
<key>NSUserActivityTypes</key>
69+
<array>
70+
<string>org.matrix.room</string>
71+
</array>
6872
<key>UIBackgroundModes</key>
6973
<array>
7074
<string>audio</string>

changelog.d/4865.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add NSUserActivity to rooms to appear in spotlight search

0 commit comments

Comments
 (0)