mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Fix rendering voice message if the waveform data is corrupted.
This commit is contained in:
parent
c6a99f1bb1
commit
1df867f345
5 changed files with 14 additions and 11 deletions
1
changelog.d/3983.bugfix
Normal file
1
changelog.d/3983.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Voice Message - Cannot render voice message if the waveform data is corrupted
|
|
@ -36,7 +36,7 @@ data class ContentAttachmentData(
|
|||
val queryUri: Uri,
|
||||
val mimeType: String?,
|
||||
val type: Type,
|
||||
val waveform: List<Int>? = null
|
||||
val waveform: List<Int?>? = null
|
||||
) : Parcelable {
|
||||
|
||||
@JsonClass(generateAdapter = false)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -33,7 +33,7 @@ internal class WaveFormSanitizer @Inject constructor() {
|
|||
* The array should have no less than 30 elements and no more than 120.
|
||||
* List of integers between zero and 1024, inclusive.
|
||||
*/
|
||||
fun sanitize(waveForm: List<Int>?): List<Int>? {
|
||||
fun sanitize(waveForm: List<Int?>?): List<Int>? {
|
||||
if (waveForm.isNullOrEmpty()) {
|
||||
return null
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ internal class WaveFormSanitizer @Inject constructor() {
|
|||
val repeatTimes = ceil(MIN_NUMBER_OF_VALUES / waveForm.size.toDouble()).toInt()
|
||||
waveForm.map { value ->
|
||||
repeat(repeatTimes) {
|
||||
sizeInRangeList.add(value)
|
||||
sizeInRangeList.add(value ?: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,12 +54,12 @@ internal class WaveFormSanitizer @Inject constructor() {
|
|||
val keepOneOf = ceil(waveForm.size.toDouble() / MAX_NUMBER_OF_VALUES).toInt()
|
||||
waveForm.mapIndexed { idx, value ->
|
||||
if (idx % keepOneOf == 0) {
|
||||
sizeInRangeList.add(value)
|
||||
sizeInRangeList.add(value ?: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
sizeInRangeList.addAll(waveForm)
|
||||
sizeInRangeList.addAll(waveForm.filterNotNull())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue