Send audio files and voice messages
vector-im/element-ios/issues/4090 - Added sendAudioFile and sendVoiceMessage methods on the MXKRoomDataSource.
MODIFY
MatrixKit/Models/Room/MXKRoomDataSource.h
MatrixKit/Models/Room/MXKRoomDataSource.h
@@ -504,6 +504,40 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure;
+/**
+ Send an audio file to the room.
+
+ While sending, a fake event will be echoed in the messages list.
+ Once complete, this local echo will be replaced by the event saved by the homeserver.
+
+ @param audioFileLocalURL the local filesystem path of the audio file to send.
+ @param mimeType the mime type of the file.
+ @param success A block object called when the operation succeeds. It returns
+ the event id of the event generated on the homeserver
+ @param failure A block object called when the operation fails.
+ */
+- (void)sendAudioFile:(NSURL *)audioFileLocalURL
+ mimeType:mimeType
+ success:(void (^)(NSString *))success
+ failure:(void (^)(NSError *))failure;
+
+/**
+ Send a voice message to the room.
+
+ While sending, a fake event will be echoed in the messages list.
+ Once complete, this local echo will be replaced by the event saved by the homeserver.
+
+ @param audioFileLocalURL the local filesystem path of the audio file to send.
+ @param mimeType (optional) the mime type of the file. Defaults to `audio/ogg`
+ @param success A block object called when the operation succeeds. It returns
+ the event id of the event generated on the homeserver
+ @param failure A block object called when the operation fails.
+ */
+- (void)sendVoiceMessage:(NSURL *)audioFileLocalURL
+ mimeType:mimeType
+ success:(void (^)(NSString *))success
+ failure:(void (^)(NSError *))failure;
+
/**
Send a file to the room.

MODIFY
MatrixKit/Models/Room/MXKRoomDataSource.m
MatrixKit/Models/Room/MXKRoomDataSource.m
@@ -1861,6 +1861,35 @@ NSString *const kMXKRoomDataSourceTimelineErrorErrorKey = @"kMXKRoomDataSourceTi
}
}
+- (void)sendAudioFile:(NSURL *)audioFileLocalURL mimeType:mimeType success:(void (^)(NSString *))success failure:(void (^)(NSError *))failure
+{
+ __block MXEvent *localEchoEvent = nil;
+
+ [_room sendAudioFile:audioFileLocalURL mimeType:mimeType localEcho:&localEchoEvent success:success failure:failure keepActualFilename:YES];
+
+ if (localEchoEvent)
+ {
+ // Make the data source digest this fake local echo message
+ [self queueEventForProcessing:localEchoEvent withRoomState:self.roomState direction:MXTimelineDirectionForwards];
+ [self processQueuedEvents:nil];
+ }
+}
+
+- (void)sendVoiceMessage:(NSURL *)audioFileLocalURL mimeType:mimeType success:(void (^)(NSString *))success failure:(void (^)(NSError *))failure
+{
+ __block MXEvent *localEchoEvent = nil;
+
+ [_room sendVoiceMessage:audioFileLocalURL mimeType:mimeType localEcho:&localEchoEvent success:success failure:failure keepActualFilename:YES];
+
+ if (localEchoEvent)
+ {
+ // Make the data source digest this fake local echo message
+ [self queueEventForProcessing:localEchoEvent withRoomState:self.roomState direction:MXTimelineDirectionForwards];
+ [self processQueuedEvents:nil];
+ }
+}
+
+
- (void)sendFile:(NSURL *)fileLocalURL mimeType:(NSString*)mimeType success:(void (^)(NSString *))success failure:(void (^)(NSError *))failure
{
__block MXEvent *localEchoEvent = nil;

Send audio files and voice messages (#829)

vector-im/element-ios/issues/4090 - Added sendAudioFile and sendVoiceMessage methods on the MXKRoomDataSource.