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:
parent
9279420c7e
commit
b83d8733e2
7 changed files with 44 additions and 13 deletions
|
|
@ -25,6 +25,10 @@ class RustMediaFile(private val inner: MediaFileHandle) : MediaFile {
|
|||
return inner.path()
|
||||
}
|
||||
|
||||
override fun persist(path: String): Boolean {
|
||||
return inner.persist(path)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
inner.close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,12 @@ class RustMediaLoader(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?, body: String?): Result<MediaFile> =
|
||||
override suspend fun downloadMediaFile(
|
||||
source: MediaSource,
|
||||
mimeType: String?,
|
||||
body: String?,
|
||||
useCache: Boolean,
|
||||
): Result<MediaFile> =
|
||||
withContext(mediaDispatcher) {
|
||||
runCatching {
|
||||
source.toRustMediaSource().use { mediaSource ->
|
||||
|
|
@ -79,7 +84,7 @@ class RustMediaLoader(
|
|||
mediaSource = mediaSource,
|
||||
body = body,
|
||||
mimeType = mimeType ?: MimeTypes.OctetStream,
|
||||
useCache = true,
|
||||
useCache = useCache,
|
||||
tempDir = cacheDirectory.path,
|
||||
)
|
||||
RustMediaFile(mediaFile)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue