mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-09 00:29:00 +01:00
Fix rendering voice message if the waveform data is corrupted.
This commit is contained in:
parent
c6a99f1bb1
commit
1df867f345
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 queryUri: Uri,
|
||||||
val mimeType: String?,
|
val mimeType: String?,
|
||||||
val type: Type,
|
val type: Type,
|
||||||
val waveform: List<Int>? = null
|
val waveform: List<Int?>? = null
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = false)
|
@JsonClass(generateAdapter = false)
|
||||||
|
@ -32,5 +32,5 @@ data class AudioWaveformInfo(
|
|||||||
* List of integers between zero and 1024, inclusive.
|
* List of integers between zero and 1024, inclusive.
|
||||||
*/
|
*/
|
||||||
@Json(name = "waveform")
|
@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.
|
* The array should have no less than 30 elements and no more than 120.
|
||||||
* List of integers between zero and 1024, inclusive.
|
* 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()) {
|
if (waveForm.isNullOrEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ internal class WaveFormSanitizer @Inject constructor() {
|
|||||||
val repeatTimes = ceil(MIN_NUMBER_OF_VALUES / waveForm.size.toDouble()).toInt()
|
val repeatTimes = ceil(MIN_NUMBER_OF_VALUES / waveForm.size.toDouble()).toInt()
|
||||||
waveForm.map { value ->
|
waveForm.map { value ->
|
||||||
repeat(repeatTimes) {
|
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()
|
val keepOneOf = ceil(waveForm.size.toDouble() / MAX_NUMBER_OF_VALUES).toInt()
|
||||||
waveForm.mapIndexed { idx, value ->
|
waveForm.mapIndexed { idx, value ->
|
||||||
if (idx % keepOneOf == 0) {
|
if (idx % keepOneOf == 0) {
|
||||||
sizeInRangeList.add(value)
|
sizeInRangeList.add(value ?: 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
sizeInRangeList.addAll(waveForm)
|
sizeInRangeList.addAll(waveForm.filterNotNull())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,11 +622,13 @@ class MessageItemFactory @Inject constructor(
|
|||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<Int>?.toFft(): List<Int>? {
|
private fun List<Int?>?.toFft(): List<Int>? {
|
||||||
return this?.map {
|
return this
|
||||||
// Value comes from AudioRecordView.maxReportableAmp, and 1024 is the max value in the Matrix spec
|
?.filterNotNull()
|
||||||
it * 22760 / 1024
|
?.map {
|
||||||
}
|
// Value comes from AudioRecordView.maxReportableAmp, and 1024 is the max value in the Matrix spec
|
||||||
|
it * 22760 / 1024
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user