From 27720aa9cf82b94023911e1fefadf34af3c50e9b Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 8 Jun 2021 14:28:01 +0300 Subject: [PATCH] vector-im/element-ios/issues/4090 - Added additional message types support and sendVoiceMessage method. --- MatrixSDK/Contrib/Swift/Data/MXRoom.swift | 28 +++++++++++++ MatrixSDK/Data/MXRoom.h | 20 ++++++++++ MatrixSDK/Data/MXRoom.m | 48 ++++++++++++++++++++--- 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/MatrixSDK/Contrib/Swift/Data/MXRoom.swift b/MatrixSDK/Contrib/Swift/Data/MXRoom.swift index c64b7eff18..48409f9e86 100644 --- a/MatrixSDK/Contrib/Swift/Data/MXRoom.swift +++ b/MatrixSDK/Contrib/Swift/Data/MXRoom.swift @@ -295,6 +295,34 @@ public extension MXRoom { return __sendAudioFile(localURL, mimeType: mimeType, localEcho: &localEcho, success: currySuccess(completion), failure: curryFailure(completion), keepActualFilename: false) } + /** + Send a voice message to the room. + + - parameters: + - localURL: the local filesystem path of the file to send. + - mimeType: the mime type of the file. + - localEcho: a pointer to a MXEvent object. + + This pointer is set to an actual MXEvent object + containing the local created event which should be used to echo the message in + the messages list until the resulting event come through the server sync. + For information, the identifier of the created local event has the prefix + `kMXEventLocalEventIdPrefix`. + + You may specify nil for this parameter if you do not want this information. + + You may provide your own MXEvent object, in this case only its send state is updated. + + - completion: A block object called when the operation completes. + - response: Provides the event id of the event generated on the home server on success. + + - returns: a `MXHTTPOperation` instance. + */ + + @nonobjc @discardableResult func sendVoiceMessage(localURL: URL, mimeType: String, localEcho: inout MXEvent?, completion: @escaping (_ response: MXResponse) -> Void) -> MXHTTPOperation { + return __sendVoiceMessage(localURL, mimeType: mimeType, localEcho: &localEcho, success: currySuccess(completion), failure: curryFailure(completion), keepActualFilename: false) + } + /** Set the topic of the room. diff --git a/MatrixSDK/Data/MXRoom.h b/MatrixSDK/Data/MXRoom.h index 75234e5ef0..a1b4552bf0 100644 --- a/MatrixSDK/Data/MXRoom.h +++ b/MatrixSDK/Data/MXRoom.h @@ -473,6 +473,26 @@ FOUNDATION_EXPORT NSString *const kMXRoomDidFlushDataNotification; failure:(void (^)(NSError *error))failure keepActualFilename:(BOOL)keepActualName NS_REFINED_FOR_SWIFT; +/** + Send a voice message to the room. + + @param fileLocalURL the local filesystem path of the file to send. + @param mimeType the mime type of the file. + @param localEcho a pointer to a MXEvent object (@see sendMessageWithContent: for details). + @param success A block object called when the operation succeeds. It returns + the event id of the event generated on the home server + @param failure A block object called when the operation fails. + @param keepActualName if YES, the filename in the local storage will be kept while sending. + + @return a MXHTTPOperation instance. + */ +- (MXHTTPOperation*)sendVoiceMessage:(NSURL*)fileLocalURL + mimeType:(NSString*)mimeType + localEcho:(MXEvent**)localEcho + success:(void (^)(NSString *eventId))success + failure:(void (^)(NSError *error))failure + keepActualFilename:(BOOL)keepActualName NS_REFINED_FOR_SWIFT; + /** Cancel a sending operation. diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index 3b4b58aef5..97bee898f6 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -1372,15 +1372,32 @@ - (MXHTTPOperation*)sendFile:(NSURL*)fileLocalURL } - (MXHTTPOperation*)sendAudioFile:(NSURL*)fileLocalURL - mimeType:(NSString*)mimeType - localEcho:(MXEvent**)localEcho - success:(void (^)(NSString *eventId))success - failure:(void (^)(NSError *error))failure - keepActualFilename:(BOOL)keepActualName + mimeType:(NSString*)mimeType + localEcho:(MXEvent**)localEcho + success:(void (^)(NSString *eventId))success + failure:(void (^)(NSError *error))failure + keepActualFilename:(BOOL)keepActualName { return [self sendFile:fileLocalURL msgType:kMXMessageTypeAudio mimeType:mimeType localEcho:localEcho success:success failure:failure keepActualFilename:keepActualName]; } +- (MXHTTPOperation*)sendVoiceMessage:(NSURL*)fileLocalURL + mimeType:(NSString*)mimeType + localEcho:(MXEvent**)localEcho + success:(void (^)(NSString *eventId))success + failure:(void (^)(NSError *error))failure + keepActualFilename:(BOOL)keepActualName +{ + return [self _sendFile:fileLocalURL + msgType:kMXMessageTypeAudio + additionalTypes:@{@"org.matrix.msc2516.voice" : @{}} + mimeType:mimeType + localEcho:localEcho + success:success + failure:failure + keepActualFilename:keepActualName]; +} + - (MXHTTPOperation*)sendFile:(NSURL*)fileLocalURL msgType:(NSString*)msgType mimeType:(NSString*)mimeType @@ -1388,6 +1405,25 @@ - (MXHTTPOperation*)sendFile:(NSURL*)fileLocalURL success:(void (^)(NSString *eventId))success failure:(void (^)(NSError *error))failure keepActualFilename:(BOOL)keepActualName +{ + return [self _sendFile:fileLocalURL + msgType:msgType + additionalTypes:nil + mimeType:mimeType + localEcho:localEcho + success:success + failure:failure + keepActualFilename:keepActualName]; +} + +- (MXHTTPOperation*)_sendFile:(NSURL*)fileLocalURL + msgType:(NSString*)msgType + additionalTypes:(NSDictionary *)additionalTypes + mimeType:(NSString*)mimeType + localEcho:(MXEvent**)localEcho + success:(void (^)(NSString *eventId))success + failure:(void (^)(NSError *error))failure + keepActualFilename:(BOOL)keepActualName { __block MXRoomOperation *roomOperation; @@ -1433,6 +1469,8 @@ - (MXHTTPOperation*)sendFile:(NSURL*)fileLocalURL } } mutableCopy]; + [msgContent addEntriesFromDictionary:additionalTypes]; + __block MXEvent *event; __block id uploaderObserver;