Don't leak MediaFileHandle when downloading voice messages (#1748)

Uses the new `MediaFile.persist()` [API](https://github.com/matrix-org/matrix-rust-sdk/pull/2789) to cache voice messages.
This allows to close the `MediaFile` handle after use and keeping the file.
Also disables rust sdk caching for voice messages as we'll use the app's cache dir for that purpose.

Fixes: https://github.com/vector-im/element-meta/issues/2175
This commit is contained in:
Marco Romano 2023-11-09 15:15:11 +01:00 committed by GitHub
parent 68cedbf8ff
commit 8f1b699271
7 changed files with 44 additions and 13 deletions

View file

@ -17,11 +17,16 @@
package io.element.android.libraries.matrix.test.media
import io.element.android.libraries.matrix.api.media.MediaFile
import java.io.File
class FakeMediaFile(private val path: String) : MediaFile {
override fun path(): String {
return path
}
override fun persist(path: String): Boolean {
return File(path()).renameTo(File(path))
}
override fun close() = Unit
}

View file

@ -42,7 +42,12 @@ class FakeMediaLoader : MatrixMediaLoader {
}
}
override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?, body: String?): Result<MediaFile> = simulateLongTask {
override suspend fun downloadMediaFile(
source: MediaSource,
mimeType: String?,
body: String?,
useCache: Boolean,
): Result<MediaFile> = simulateLongTask {
if (shouldFail) {
Result.failure(RuntimeException())
} else {