Split VoiceMessageType from AudioMessageType (#1664)
Currently, for compatibility reasons, we implement MSC3245v1 which puts the voice data inside an audio message type. Though at times it seems impractical to deal with a single message type which effectively represents 2 different kinds of messages.
This PR creates a new message type called `VoiceMessageType` which is used whenever we receive an event with `"msgtype": "m.audio"` which also has the `"org.matrix.msc3245.voice": {}` field. This makes it easier to process voice messages as different entities throughout the rest of the codebase.
This commit is contained in:
parent
473c8abc82
commit
a07286ace9
7 changed files with 76 additions and 55 deletions
|
|
@ -50,6 +50,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.UnableToDecry
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.UnknownContent
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.UnknownMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.VoiceMessageType
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import javax.inject.Inject
|
||||
|
|
@ -128,11 +129,10 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
|
|||
sp.getString(CommonStrings.common_file)
|
||||
}
|
||||
is AudioMessageType -> {
|
||||
if (messageType.isVoiceMessage) {
|
||||
sp.getString(CommonStrings.common_voice_message)
|
||||
} else {
|
||||
sp.getString(CommonStrings.common_audio)
|
||||
}
|
||||
sp.getString(CommonStrings.common_audio)
|
||||
}
|
||||
is VoiceMessageType -> {
|
||||
sp.getString(CommonStrings.common_voice_message)
|
||||
}
|
||||
is OtherMessageType -> {
|
||||
messageType.body
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.UnableToDecry
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.UnknownContent
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.UnknownMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.VoiceMessageType
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.room.aPollContent
|
||||
|
|
@ -162,8 +163,8 @@ class DefaultRoomLastMessageFormatterTest {
|
|||
val sharedContentMessagesTypes = arrayOf(
|
||||
TextMessageType(body, null),
|
||||
VideoMessageType(body, MediaSource("url"), null),
|
||||
AudioMessageType(body, MediaSource("url"), null, null, false),
|
||||
AudioMessageType(body, MediaSource("url"), null, null, true),
|
||||
AudioMessageType(body, MediaSource("url"), null),
|
||||
VoiceMessageType(body, MediaSource("url"), null, null),
|
||||
ImageMessageType(body, MediaSource("url"), null),
|
||||
FileMessageType(body, MediaSource("url"), null),
|
||||
LocationMessageType(body, "geo:1,2", null),
|
||||
|
|
@ -199,12 +200,8 @@ class DefaultRoomLastMessageFormatterTest {
|
|||
for ((type, result) in resultsInDm) {
|
||||
val expectedResult = when (type) {
|
||||
is VideoMessageType -> "Video"
|
||||
is AudioMessageType -> {
|
||||
when (type.isVoiceMessage) {
|
||||
true -> "Voice message"
|
||||
false -> "Audio"
|
||||
}
|
||||
}
|
||||
is AudioMessageType -> "Audio"
|
||||
is VoiceMessageType -> "Voice message"
|
||||
is ImageMessageType -> "Image"
|
||||
is FileMessageType -> "File"
|
||||
is LocationMessageType -> "Shared location"
|
||||
|
|
@ -222,12 +219,8 @@ class DefaultRoomLastMessageFormatterTest {
|
|||
val string = result.toString()
|
||||
val expectedResult = when (type) {
|
||||
is VideoMessageType -> "$senderName: Video"
|
||||
is AudioMessageType -> {
|
||||
when (type.isVoiceMessage) {
|
||||
true -> "$senderName: Voice message"
|
||||
false -> "$senderName: Audio"
|
||||
}
|
||||
}
|
||||
is AudioMessageType -> "$senderName: Audio"
|
||||
is VoiceMessageType -> "$senderName: Voice message"
|
||||
is ImageMessageType -> "$senderName: Image"
|
||||
is FileMessageType -> "$senderName: File"
|
||||
is LocationMessageType -> "$senderName: Shared location"
|
||||
|
|
@ -239,12 +232,8 @@ class DefaultRoomLastMessageFormatterTest {
|
|||
}
|
||||
val shouldCreateAnnotatedString = when (type) {
|
||||
is VideoMessageType -> true
|
||||
is AudioMessageType -> {
|
||||
when (type.isVoiceMessage) {
|
||||
true -> true
|
||||
false -> true
|
||||
}
|
||||
}
|
||||
is AudioMessageType -> true
|
||||
is VoiceMessageType -> true
|
||||
is ImageMessageType -> true
|
||||
is FileMessageType -> true
|
||||
is LocationMessageType -> false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue