add getFileUrl extension

This commit is contained in:
Benoit Marty 2019-07-09 11:20:00 +02:00
parent 058e7153a1
commit 9a4eb8e9a4
7 changed files with 22 additions and 12 deletions

View file

@ -42,7 +42,7 @@ data class MessageAudioContent(
/**
* Required. Required if the file is not encrypted. The URL (typically MXC URI) to the audio clip.
*/
@Json(name = "url") val url: String? = null,
@Json(name = "url") override val url: String? = null,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "m.new_content") override val newContent: Content? = null,

View file

@ -20,8 +20,18 @@ import im.vector.matrix.android.internal.crypto.model.rest.EncryptedFileInfo
/**
* Interface for message which can contains encrypted data
* Interface for message which can contains an encrypted file
*/
interface MessageEncryptedContent : MessageContent {
/**
* Required. Required if the file is unencrypted. The URL (typically MXC URI) to the image.
*/
val url: String?
val encryptedFileInfo: EncryptedFileInfo?
}
/**
* Get the url of the encrypted file or of the file
*/
fun MessageEncryptedContent.getFileUrl() = encryptedFileInfo?.url ?: url

View file

@ -48,7 +48,7 @@ data class MessageFileContent(
/**
* Required. Required if the file is unencrypted. The URL (typically MXC URI) to the file.
*/
@Json(name = "url") val url: String? = null,
@Json(name = "url") override val url: String? = null,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "m.new_content") override val newContent: Content? = null,

View file

@ -43,7 +43,7 @@ data class MessageImageContent(
/**
* Required. Required if the file is unencrypted. The URL (typically MXC URI) to the image.
*/
@Json(name = "url") val url: String? = null,
@Json(name = "url") override val url: String? = null,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "m.new_content") override val newContent: Content? = null,

View file

@ -42,7 +42,7 @@ data class MessageVideoContent(
/**
* Required. Required if the file is unencrypted. The URL (typically MXC URI) to the video clip.
*/
@Json(name = "url") val url: String? = null,
@Json(name = "url") override val url: String? = null,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "m.new_content") override val newContent: Content? = null,

View file

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

View file

@ -185,7 +185,7 @@ class MessageItemFactory @Inject constructor(
val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize()
val data = ImageContentRenderer.Data(
filename = messageContent.body,
url = messageContent.encryptedFileInfo?.url ?: messageContent.url,
url = messageContent.getFileUrl(),
elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(),
height = messageContent.info?.height,
maxHeight = maxHeight,
@ -238,7 +238,7 @@ class MessageItemFactory @Inject constructor(
val videoData = VideoContentRenderer.Data(
eventId = informationData.eventId,
filename = messageContent.body,
url = messageContent.encryptedFileInfo?.url ?: messageContent.url,
url = messageContent.getFileUrl(),
elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(),
thumbnailMediaData = thumbnailData
)