Skip to content

Commit cb96886

Browse files
author
Onuray Sahin
committed
Send voice message.
1 parent 69350ef commit cb96886

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

matrix-sdk-android-rx/src/main/java/org/matrix/android/sdk/rx/RxRoom.kt

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import io.reactivex.Single
2323
import kotlinx.coroutines.rx2.rxCompletable
2424
import kotlinx.coroutines.rx2.rxSingle
2525
import org.matrix.android.sdk.api.query.QueryStringValue
26+
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
2627
import org.matrix.android.sdk.api.session.events.model.Event
2728
import org.matrix.android.sdk.api.session.identity.ThreePid
2829
import org.matrix.android.sdk.api.session.room.Room
@@ -146,6 +147,10 @@ class RxRoom(private val room: Room) {
146147
fun deleteAvatar(): Completable = rxCompletable {
147148
room.deleteAvatar()
148149
}
150+
151+
fun sendMedia(attachment: ContentAttachmentData, compressBeforeSending: Boolean, roomIds: Set<String>): Completable = rxCompletable {
152+
room.sendMedia(attachment, compressBeforeSending, roomIds)
153+
}
149154
}
150155

151156
fun Room.rx(): RxRoom {

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageAudioContent.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.squareup.moshi.Json
2020
import com.squareup.moshi.JsonClass
2121
import org.matrix.android.sdk.api.session.events.model.Content
2222
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
23+
import org.matrix.android.sdk.internal.crypto.model.rest.AudioWaveformInfo
2324
import org.matrix.android.sdk.internal.crypto.model.rest.EncryptedFileInfo
2425

2526
@JsonClass(generateAdapter = true)
@@ -50,7 +51,17 @@ data class MessageAudioContent(
5051
/**
5152
* Required if the file is encrypted. Information on the encrypted file, as specified in End-to-end encryption.
5253
*/
53-
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
54+
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null,
55+
56+
/**
57+
* Encapsulates waveform and duration of the audio.
58+
*/
59+
@Json(name = "org.matrix.msc1767.audio") val audioWaveformInfo: AudioWaveformInfo? = null,
60+
61+
/**
62+
* Indicates that is a voice message.
63+
*/
64+
@Json(name = "org.matrix.msc2516.voice") val voiceMessageIndicator: Any? = null
5465
) : MessageWithAttachmentContent {
5566

5667
override val mimeType: String?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 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+
package org.matrix.android.sdk.internal.crypto.model.rest
18+
19+
import com.squareup.moshi.Json
20+
import com.squareup.moshi.JsonClass
21+
22+
@JsonClass(generateAdapter = true)
23+
data class AudioWaveformInfo(
24+
@Json(name = "duration")
25+
val duration: Long? = null,
26+
27+
@Json(name = "waveform")
28+
val waveform: List<Int>? = null
29+
30+
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import org.matrix.android.sdk.api.session.room.model.relation.ReplyToContent
5353
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
5454
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
5555
import org.matrix.android.sdk.api.session.room.timeline.isReply
56+
import org.matrix.android.sdk.internal.crypto.model.rest.AudioWaveformInfo
5657
import org.matrix.android.sdk.internal.di.UserId
5758
import org.matrix.android.sdk.internal.session.content.ThumbnailExtractor
5859
import org.matrix.android.sdk.internal.session.permalinks.PermalinkFactory
@@ -289,14 +290,20 @@ internal class LocalEchoEventFactory @Inject constructor(
289290
}
290291

291292
private fun createAudioEvent(roomId: String, attachment: ContentAttachmentData): Event {
293+
val isVoiceMessage = attachment.mimeType == "audio/ogg"
292294
val content = MessageAudioContent(
293295
msgType = MessageType.MSGTYPE_AUDIO,
294296
body = attachment.name ?: "audio",
295297
audioInfo = AudioInfo(
296298
mimeType = attachment.getSafeMimeType()?.takeIf { it.isNotBlank() },
297299
size = attachment.size
298300
),
299-
url = attachment.queryUri.toString()
301+
url = attachment.queryUri.toString(),
302+
audioWaveformInfo = if (!isVoiceMessage) null else AudioWaveformInfo(
303+
duration = attachment.duration,
304+
waveform = null // TODO.
305+
),
306+
voiceMessageIndicator = if (!isVoiceMessage) null else Any()
300307
)
301308
return createMessageEvent(roomId, content)
302309
}

multipicker/src/main/java/im/vector/lib/multipicker/utils/ContentResolverUtil.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal fun Uri.toMultiPickerVideoType(context: Context): MultiPickerVideoType?
111111
}
112112
}
113113

114-
internal fun Uri.toMultiPickerAudioType(context: Context): MultiPickerAudioType? {
114+
fun Uri.toMultiPickerAudioType(context: Context): MultiPickerAudioType? {
115115
val projection = arrayOf(
116116
MediaStore.Audio.Media.DISPLAY_NAME,
117117
MediaStore.Audio.Media.SIZE

0 commit comments

Comments
 (0)