1717 limitations under the License.
1818 */
1919
20+ @import Intents;
21+
2022#import " MXKRoomDataSource.h"
2123
2224@import MatrixSDK;
@@ -1698,6 +1700,37 @@ - (void)paginateToFillRect:(CGRect)rect direction:(MXTimelineDirection)direction
16981700
16991701
17001702#pragma mark - Sending
1703+
1704+ - (INPerson *)intentRecipient API_AVAILABLE(ios(15 ))
1705+ {
1706+
1707+ INPersonHandle *personHandle;
1708+ INPerson *person;
1709+
1710+ if ([_room isDirect ]) {
1711+ MXUser *user = [_room.mxSession userWithUserId: [_room directUserId ]];
1712+
1713+ personHandle = [[INPersonHandle alloc ] initWithValue: user.userId type: INPersonHandleTypeUnknown];
1714+ // TODO: avata url to INImage
1715+ person = [[INPerson alloc ] initWithPersonHandle: personHandle nameComponents: NULL displayName: user.displayname image: NULL contactIdentifier: NULL customIdentifier: user.userId isMe: NO suggestionType: INPersonSuggestionTypeInstantMessageAddress];
1716+ } else {
1717+ personHandle = [[INPersonHandle alloc ] initWithValue: _room.roomId type: INPersonHandleTypeUnknown];
1718+ // TODO: root avatar url to INImage
1719+ person = [[INPerson alloc ] initWithPersonHandle: personHandle nameComponents: NULL displayName: _room.summary.displayname image: NULL contactIdentifier: NULL customIdentifier: _room.roomId isMe: NO suggestionType: INPersonSuggestionTypeNone];
1720+ // TODO: groupName = [[INSpeakableString alloc] initWithSpokenPhrase:_room.summary.displayname];
1721+ }
1722+
1723+ return person;
1724+ }
1725+
1726+ - (nullable INSpeakableString *)intentGroupName API_AVAILABLE(ios(15 ))
1727+ {
1728+ if (![_room isDirect ]) {
1729+ return [[INSpeakableString alloc ] initWithSpokenPhrase: _room.summary.displayname];
1730+ }
1731+ return NULL ;
1732+ }
1733+
17011734- (void )sendTextMessage : (NSString *)text success : (void (^)(NSString *))success failure : (void (^)(NSError *))failure
17021735{
17031736 __block MXEvent *localEchoEvent = nil ;
@@ -1706,6 +1739,15 @@ - (void)sendTextMessage:(NSString *)text success:(void (^)(NSString *))success f
17061739 NSString *sanitizedText = [self sanitizedMessageText: text];
17071740 NSString *html = [self htmlMessageFromSanitizedText: sanitizedText];
17081741
1742+ // Donate an intent
1743+ if (@available (iOS 15.0 , *)) {
1744+ NSArray <INPerson *> *recipients = [[NSArray alloc ] initWithObjects: [self intentRecipient ], nil ];
1745+ INSendMessageIntent *intent = [[INSendMessageIntent alloc ] initWithRecipients: recipients outgoingMessageType: INOutgoingMessageTypeOutgoingMessageText content: sanitizedText speakableGroupName: [self intentGroupName ] conversationIdentifier: self ->_roomId serviceName: @" matrix" sender: NULL ];
1746+
1747+ INInteraction *interaction = [[INInteraction alloc ] initWithIntent: intent response: NULL ];
1748+ [interaction donateInteractionWithCompletion: NULL ];
1749+ }
1750+
17091751 // Make the request to the homeserver
17101752 if (isEmote)
17111753 {
@@ -1822,6 +1864,14 @@ - (void)sendImage:(UIImage *)image success:(void (^)(NSString *))success failure
18221864 }
18231865 }
18241866
1867+ if (@available (ios 15 , *)) {
1868+ NSArray <INPerson *> *recipients = [[NSArray alloc ] initWithObjects: [self intentRecipient ], nil ];
1869+ INSendMessageIntent *intent = [[INSendMessageIntent alloc ] initWithRecipients: recipients outgoingMessageType: INOutgoingMessageTypeOutgoingMessageText content: NULL speakableGroupName: [self intentGroupName ] conversationIdentifier: self ->_roomId serviceName: @" matrix" sender: NULL ];
1870+
1871+ INInteraction *interaction = [[INInteraction alloc ] initWithIntent: intent response: NULL ];
1872+ [interaction donateInteractionWithCompletion: NULL ];
1873+ }
1874+
18251875 [self sendImageData: imageData withImageSize: image.size mimeType: mimetype andThumbnail: thumbnail success: success failure: failure];
18261876}
18271877
@@ -1874,6 +1924,15 @@ - (void)sendVideoAsset:(AVAsset *)videoAsset withThumbnail:(UIImage *)videoThumb
18741924{
18751925 __block MXEvent *localEchoEvent = nil ;
18761926
1927+ // Donate an intent
1928+ if (@available (iOS 15.0 , *)) {
1929+ NSArray <INPerson *> *recipients = [[NSArray alloc ] initWithObjects: [self intentRecipient ], nil ];
1930+ INSendMessageIntent *intent = [[INSendMessageIntent alloc ] initWithRecipients: recipients outgoingMessageType: INOutgoingMessageTypeOutgoingMessageText content: NULL speakableGroupName: [self intentGroupName ] conversationIdentifier: self ->_roomId serviceName: @" matrix" sender: NULL ];
1931+
1932+ INInteraction *interaction = [[INInteraction alloc ] initWithIntent: intent response: NULL ];
1933+ [interaction donateInteractionWithCompletion: NULL ];
1934+ }
1935+
18771936 [_room sendVideoAsset: videoAsset withThumbnail: videoThumbnail localEcho: &localEchoEvent success: success failure: failure];
18781937
18791938 if (localEchoEvent)
@@ -1888,6 +1947,17 @@ - (void)sendAudioFile:(NSURL *)audioFileLocalURL mimeType:mimeType success:(void
18881947{
18891948 __block MXEvent *localEchoEvent = nil ;
18901949
1950+ // Donate an intent
1951+ if (@available (iOS 15.0 , *)) {
1952+ NSArray <INPerson *> *recipients = [[NSArray alloc ] initWithObjects: [self intentRecipient ], nil ];
1953+ INSendMessageAttachment *attachment = [INSendMessageAttachment attachmentWithAudioMessageFile: [INFile fileWithFileURL: audioFileLocalURL filename: NULL typeIdentifier: mimeType]];
1954+
1955+ INSendMessageIntent *intent = [[INSendMessageIntent alloc ] initWithRecipients: recipients outgoingMessageType: INOutgoingMessageTypeOutgoingMessageText content: NULL speakableGroupName: [self intentGroupName ] conversationIdentifier: self ->_roomId serviceName: @" matrix" sender: NULL attachments: [[NSArray alloc ] initWithObjects: attachment, nil ]];
1956+
1957+ INInteraction *interaction = [[INInteraction alloc ] initWithIntent: intent response: NULL ];
1958+ [interaction donateInteractionWithCompletion: NULL ];
1959+ }
1960+
18911961 [_room sendAudioFile: audioFileLocalURL mimeType: mimeType localEcho: &localEchoEvent success: success failure: failure keepActualFilename: YES ];
18921962
18931963 if (localEchoEvent)
@@ -1907,6 +1977,17 @@ - (void)sendVoiceMessage:(NSURL *)audioFileLocalURL
19071977{
19081978 __block MXEvent *localEchoEvent = nil ;
19091979
1980+ // Donate an intent
1981+ if (@available (iOS 15.0 , *)) {
1982+ NSArray <INPerson *> *recipients = [[NSArray alloc ] initWithObjects: [self intentRecipient ], nil ];
1983+ INSendMessageAttachment *attachment = [INSendMessageAttachment attachmentWithAudioMessageFile: [INFile fileWithFileURL: audioFileLocalURL filename: NULL typeIdentifier: mimeType]];
1984+
1985+ INSendMessageIntent *intent = [[INSendMessageIntent alloc ] initWithRecipients: recipients outgoingMessageType: INOutgoingMessageTypeOutgoingMessageText content: NULL speakableGroupName: [self intentGroupName ] conversationIdentifier: self ->_roomId serviceName: @" matrix" sender: NULL attachments: [[NSArray alloc ] initWithObjects: attachment, nil ]];
1986+
1987+ INInteraction *interaction = [[INInteraction alloc ] initWithIntent: intent response: NULL ];
1988+ [interaction donateInteractionWithCompletion: NULL ];
1989+ }
1990+
19101991 [_room sendVoiceMessage: audioFileLocalURL mimeType: mimeType duration: duration samples: samples localEcho: &localEchoEvent success: success failure: failure keepActualFilename: YES ];
19111992
19121993 if (localEchoEvent)
@@ -1922,6 +2003,15 @@ - (void)sendFile:(NSURL *)fileLocalURL mimeType:(NSString*)mimeType success:(voi
19222003{
19232004 __block MXEvent *localEchoEvent = nil ;
19242005
2006+ // Donate an intent
2007+ if (@available (iOS 15.0 , *)) {
2008+ NSArray <INPerson *> *recipients = [[NSArray alloc ] initWithObjects: [self intentRecipient ], nil ];
2009+ INSendMessageIntent *intent = [[INSendMessageIntent alloc ] initWithRecipients: recipients outgoingMessageType: INOutgoingMessageTypeOutgoingMessageText content: NULL speakableGroupName: [self intentGroupName ] conversationIdentifier: self ->_roomId serviceName: @" matrix" sender: NULL ];
2010+
2011+ INInteraction *interaction = [[INInteraction alloc ] initWithIntent: intent response: NULL ];
2012+ [interaction donateInteractionWithCompletion: NULL ];
2013+ }
2014+
19252015 [_room sendFile: fileLocalURL mimeType: mimeType localEcho: &localEchoEvent success: success failure: failure];
19262016
19272017 if (localEchoEvent)
0 commit comments