Skip to content

Commit

Permalink
element-hq/element-ios/issues/4090 - Added additional message types s…
Browse files Browse the repository at this point in the history
…upport and sendVoiceMessage method.
  • Loading branch information
stefanceriu committed Jun 8, 2021
1 parent 32614df commit 27720aa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
28 changes: 28 additions & 0 deletions MatrixSDK/Contrib/Swift/Data/MXRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?>) -> Void) -> MXHTTPOperation {
return __sendVoiceMessage(localURL, mimeType: mimeType, localEcho: &localEcho, success: currySuccess(completion), failure: curryFailure(completion), keepActualFilename: false)
}

/**
Set the topic of the room.
Expand Down
20 changes: 20 additions & 0 deletions MatrixSDK/Data/MXRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
48 changes: 43 additions & 5 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -1372,22 +1372,58 @@ - (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
localEcho:(MXEvent**)localEcho
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;

Expand Down Expand Up @@ -1433,6 +1469,8 @@ - (MXHTTPOperation*)sendFile:(NSURL*)fileLocalURL
}
} mutableCopy];

[msgContent addEntriesFromDictionary:additionalTypes];

__block MXEvent *event;
__block id uploaderObserver;

Expand Down

0 comments on commit 27720aa

Please sign in to comment.