@@ -261,6 +261,8 @@ class RemoteFileDownloadWorker @AssistedInject constructor(
261
261
private const val ARG_COMMUNITY_ROOM_ID = " community_room_id"
262
262
private const val ARG_COMMUNITY_FILE_ID = " community_file_id"
263
263
264
+ private const val SUBDIRECTORY = " remote_files"
265
+
264
266
private fun RemoteFile.sha256Hash (): String {
265
267
val hash = MessageDigest .getInstance(" SHA-256" )
266
268
when (this ) {
@@ -278,9 +280,12 @@ class RemoteFileDownloadWorker @AssistedInject constructor(
278
280
return hash.digest().toHexString()
279
281
}
280
282
283
+ private fun downloadsDirectory (context : Context ): File =
284
+ File (context.cacheDir, SUBDIRECTORY )
285
+
281
286
// Deterministically get the file path for the given remote file.
282
287
fun computeFileName (context : Context , remote : RemoteFile ): File {
283
- return File (context.cacheDir, " remote_files/ ${ remote.sha256Hash()} " )
288
+ return File (downloadsDirectory( context), remote.sha256Hash())
284
289
}
285
290
286
291
fun cancelAll (context : Context ) {
@@ -297,6 +302,12 @@ class RemoteFileDownloadWorker @AssistedInject constructor(
297
302
)
298
303
}
299
304
305
+ /* * Returns all currently downloaded files (may be empty). */
306
+ fun listDownloadedFiles (context : Context ): List <File > {
307
+ val directory = downloadsDirectory(context)
308
+ return directory.listFiles()?.toList().orEmpty()
309
+ }
310
+
300
311
/* *
301
312
* @param isOldAvatarOf used to indicate that this file is an avatar of a specific address. This
302
313
* information is optional and only used for migration purposes (to move the avatar from
0 commit comments