mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
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:
+7
-1
@@ -35,7 +35,13 @@ interface MatrixMediaLoader {
|
||||
* @param source to fetch the data for.
|
||||
* @param mimeType: optional mime type.
|
||||
* @param body: optional body which will be used to name the file.
|
||||
* @param useCache: if true, the rust sdk will cache the media in its store.
|
||||
* @return a [Result] of [MediaFile]
|
||||
*/
|
||||
suspend fun downloadMediaFile(source: MediaSource, mimeType: String?, body: String?): Result<MediaFile>
|
||||
suspend fun downloadMediaFile(
|
||||
source: MediaSource,
|
||||
mimeType: String?,
|
||||
body: String?,
|
||||
useCache: Boolean = true,
|
||||
): Result<MediaFile>
|
||||
}
|
||||
|
||||
+7
-1
@@ -21,10 +21,16 @@ import java.io.File
|
||||
|
||||
/**
|
||||
* A wrapper around a media file on the disk.
|
||||
* When closed the file will be removed from the disk.
|
||||
* When closed the file will be removed from the disk unless [persist] has been used.
|
||||
*/
|
||||
interface MediaFile : Closeable {
|
||||
fun path(): String
|
||||
|
||||
/**
|
||||
* Persists the temp file to the given path. The file will be moved to
|
||||
* the given path and won't be deleted anymore when closing the handle.
|
||||
*/
|
||||
fun persist(path: String): Boolean
|
||||
}
|
||||
|
||||
fun MediaFile.toFile(): File {
|
||||
|
||||
Reference in New Issue
Block a user