This commit is contained in:
Benoit Marty 2019-07-09 11:05:25 +02:00
parent d7b2371854
commit 058e7153a1
2 changed files with 7 additions and 7 deletions

View File

@ -62,11 +62,9 @@ internal class DefaultFileService @Inject constructor(private val context: Conte
val folder = getFolder(downloadMode, id)

File(folder, fileName)
}.map { destFile ->
if (!destFile.exists()) {
}.flatMap { destFile ->
if (!destFile.exists() || downloadMode == FileService.DownloadMode.TO_EXPORT) {
Try {
Timber.v("## decrypt file")

val resolvedUrl = contentUrlResolver.resolveFullSize(url) ?: throw IllegalArgumentException("url is null")

val request = Request.Builder()
@ -82,6 +80,7 @@ internal class DefaultFileService @Inject constructor(private val context: Conte
}

if (elementToDecrypt != null) {
Timber.v("## decrypt file")
MXEncryptedAttachments.decryptAttachment(inputStream, elementToDecrypt) ?: throw IllegalStateException("Decryption error")
} else {
inputStream
@ -89,10 +88,11 @@ internal class DefaultFileService @Inject constructor(private val context: Conte
}
.map { inputStream ->
writeToFile(inputStream, destFile)
destFile
}
} else {
Try.just(destFile)
}

destFile
}
}
.foldToCallback(callback)

View File

@ -452,7 +452,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
FileService.DownloadMode.TO_EXPORT,
action.eventId,
action.messageFileContent.getFileName(),
action.messageFileContent.url,
action.messageFileContent.encryptedFileInfo?.url ?: action.messageFileContent.url,
action.messageFileContent.encryptedFileInfo?.toElementToDecrypt(),
object : MatrixCallback<File> {
override fun onSuccess(data: File) {