Download file - typo

This commit is contained in:
Benoit Marty 2019-07-09 10:33:23 +02:00
parent a07f8b615e
commit b0c939866f
6 changed files with 21 additions and 15 deletions

View File

@ -51,4 +51,4 @@ data class MessageAudioContent(
* Required if the file is encrypted. Information on the encrypted file, as specified in End-to-end encryption.
*/
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
) : MessageEncyptedContent
) : MessageEncryptedContent

View File

@ -22,6 +22,6 @@ import im.vector.matrix.android.internal.crypto.model.rest.EncryptedFileInfo
/**
* Interface for message which can contains encrypted data
*/
interface MessageEncyptedContent : MessageContent {
interface MessageEncryptedContent : MessageContent {
val encryptedFileInfo: EncryptedFileInfo?
}

View File

@ -16,6 +16,7 @@

package im.vector.matrix.android.api.session.room.model.message

import android.content.ClipDescription
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.session.events.model.Content
@ -53,4 +54,16 @@ data class MessageFileContent(
@Json(name = "m.new_content") override val newContent: Content? = null,

@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
) : MessageEncyptedContent
) : MessageEncryptedContent {

fun getMimeType(): String {
// Mimetype default to plain text, should not be used
return encryptedFileInfo?.mimetype
?: info?.mimeType
?: ClipDescription.MIMETYPE_TEXT_PLAIN
}

fun getFileName(): String {
return filename ?: body
}
}

View File

@ -52,4 +52,4 @@ data class MessageImageContent(
* Required if the file is encrypted. Information on the encrypted file, as specified in End-to-end encryption.
*/
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
) : MessageEncyptedContent
) : MessageEncryptedContent

View File

@ -51,4 +51,4 @@ data class MessageVideoContent(
* Required if the file is encrypted. Information on the encrypted file, as specified in End-to-end encryption.
*/
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
) : MessageEncyptedContent
) : MessageEncryptedContent

View File

@ -16,7 +16,6 @@

package im.vector.riotx.features.home.room.detail

import android.content.ClipDescription
import android.net.Uri
import android.text.TextUtils
import androidx.lifecycle.LiveData
@ -452,16 +451,13 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
session.downloadFile(
FileService.DownloadMode.TO_EXPORT,
action.eventId,
action.messageFileContent.filename ?: "file.dat",
action.messageFileContent.getFileName(),
action.messageFileContent.url,
action.messageFileContent.encryptedFileInfo?.toElementToDecrypt(),
object : MatrixCallback<File> {
override fun onSuccess(data: File) {
_downloadedFileEvent.postValue(LiveEvent(DownloadFileState(
// Mimetype default to plain text, should not be used
action.messageFileContent.encryptedFileInfo?.mimetype
?: action.messageFileContent.info?.mimeType
?: ClipDescription.MIMETYPE_TEXT_PLAIN,
action.messageFileContent.getMimeType(),
data,
null
)))
@ -469,10 +465,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro

override fun onFailure(failure: Throwable) {
_downloadedFileEvent.postValue(LiveEvent(DownloadFileState(
// Mimetype default to plain text, should not be used
action.messageFileContent.encryptedFileInfo?.mimetype
?: action.messageFileContent.info?.mimeType
?: ClipDescription.MIMETYPE_TEXT_PLAIN,
action.messageFileContent.getMimeType(),
null,
failure
)))