From b0c939866f07e59f5addc462eb100e77af7a9701 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 9 Jul 2019 10:33:23 +0200 Subject: [PATCH] Download file - typo --- .../room/model/message/MessageAudioContent.kt | 2 +- ...yptedContent.kt => MessageEncryptedContent.kt} | 2 +- .../room/model/message/MessageFileContent.kt | 15 ++++++++++++++- .../room/model/message/MessageImageContent.kt | 2 +- .../room/model/message/MessageVideoContent.kt | 2 +- .../home/room/detail/RoomDetailViewModel.kt | 13 +++---------- 6 files changed, 21 insertions(+), 15 deletions(-) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/{MessageEncyptedContent.kt => MessageEncryptedContent.kt} (94%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt index 7a9ccf7ace..6987804c0f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt @@ -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 \ No newline at end of file +) : MessageEncryptedContent diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEncyptedContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEncryptedContent.kt similarity index 94% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEncyptedContent.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEncryptedContent.kt index 3a98701c2f..88123be384 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEncyptedContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEncryptedContent.kt @@ -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? } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt index 1b7f179885..f29a6fa9e5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt @@ -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 \ No newline at end of file +) : 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 + } +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt index 50feb4841f..15ee19c42c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt @@ -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 \ No newline at end of file +) : MessageEncryptedContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt index 11845d4df7..e741e2f2e1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt @@ -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 \ No newline at end of file +) : MessageEncryptedContent \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 0c1b45238b..336179a66c 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -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 { 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 )))