Merge pull request #3984 from vector-im/feature/ons/fix_voice_message_rendering

Fix rendering voice message if the waveform data is corrupted
This commit is contained in:
Benoit Marty 2021-09-08 15:21:33 +02:00 committed by GitHub
commit 88bb845910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

1
changelog.d/3983.bugfix Normal file
View File

@ -0,0 +1 @@
Voice Message - Cannot render voice message if the waveform data is corrupted

View File

@ -32,5 +32,5 @@ data class AudioWaveformInfo(
* List of integers between zero and 1024, inclusive.
*/
@Json(name = "waveform")
val waveform: List<Int>? = null
val waveform: List<Int?>? = null
)

View File

@ -185,7 +185,7 @@ internal class DefaultSendService @AssistedInject constructor(
name = messageContent.body,
queryUri = Uri.parse(messageContent.url),
type = ContentAttachmentData.Type.AUDIO,
waveform = messageContent.audioWaveformInfo?.waveform
waveform = messageContent.audioWaveformInfo?.waveform?.filterNotNull()
)
localEchoRepository.updateSendState(localEcho.eventId, roomId, SendState.UNSENT)
internalSendMedia(listOf(localEcho.root), attachmentData, true)

View File

@ -622,8 +622,10 @@ class MessageItemFactory @Inject constructor(
.highlighted(highlight)
}
private fun List<Int>?.toFft(): List<Int>? {
return this?.map {
private fun List<Int?>?.toFft(): List<Int>? {
return this
?.filterNotNull()
?.map {
// Value comes from AudioRecordView.maxReportableAmp, and 1024 is the max value in the Matrix spec
it * 22760 / 1024
}