From 12c4f3c6f77faaeca456dd15ec4c44a10623ffcd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 3 May 2021 20:25:49 +0200 Subject: [PATCH] Fix video thumbnail not displayed in when replying and in bottom sheet Also create some extensions for future use --- .../sdk/api/session/room/model/message/FileInfo.kt | 7 +++++++ .../sdk/api/session/room/model/message/ImageInfo.kt | 7 +++++++ .../api/session/room/model/message/LocationInfo.kt | 7 +++++++ .../sdk/api/session/room/model/message/VideoInfo.kt | 7 +++++++ .../detail/timeline/factory/MessageItemFactory.kt | 4 ++-- .../timeline/image/ImageContentRendererFactory.kt | 12 +++++++----- .../features/media/RoomEventsAttachmentProvider.kt | 7 +++---- .../uploads/media/RoomUploadsMediaFragment.kt | 4 ++-- .../uploads/media/UploadsMediaController.kt | 3 ++- 9 files changed, 44 insertions(+), 14 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/FileInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/FileInfo.kt index e85bb0800a..f21074096e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/FileInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/FileInfo.kt @@ -47,3 +47,10 @@ data class FileInfo( */ @Json(name = "thumbnail_file") val thumbnailFile: EncryptedFileInfo? = null ) + +/** + * Get the url of the encrypted thumbnail or of the thumbnail + */ +fun FileInfo.getThumbnailUrl(): String? { + return thumbnailFile?.url ?: thumbnailUrl +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/ImageInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/ImageInfo.kt index 048febec39..deadcc3f34 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/ImageInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/ImageInfo.kt @@ -57,3 +57,10 @@ data class ImageInfo( */ @Json(name = "thumbnail_file") val thumbnailFile: EncryptedFileInfo? = null ) + +/** + * Get the url of the encrypted thumbnail or of the thumbnail + */ +fun ImageInfo.getThumbnailUrl(): String? { + return thumbnailFile?.url ?: thumbnailUrl +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt index a6908dce5b..a76c3c5b64 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt @@ -37,3 +37,10 @@ data class LocationInfo( */ @Json(name = "thumbnail_file") val thumbnailFile: EncryptedFileInfo? = null ) + +/** + * Get the url of the encrypted thumbnail or of the thumbnail + */ +fun LocationInfo.getThumbnailUrl(): String? { + return thumbnailFile?.url ?: thumbnailUrl +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/VideoInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/VideoInfo.kt index 8379ee9338..8a36c26313 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/VideoInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/VideoInfo.kt @@ -62,3 +62,10 @@ data class VideoInfo( */ @Json(name = "thumbnail_file") val thumbnailFile: EncryptedFileInfo? = null ) + +/** + * Get the url of the encrypted thumbnail or of the thumbnail + */ +fun VideoInfo.getThumbnailUrl(): String? { + return thumbnailFile?.url ?: thumbnailUrl +} diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 0f214ffb13..63770e4538 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -85,6 +85,7 @@ import org.matrix.android.sdk.api.session.room.model.message.OPTION_TYPE_BUTTONS import org.matrix.android.sdk.api.session.room.model.message.OPTION_TYPE_POLL import org.matrix.android.sdk.api.session.room.model.message.getFileName import org.matrix.android.sdk.api.session.room.model.message.getFileUrl +import org.matrix.android.sdk.api.session.room.model.message.getThumbnailUrl import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent import org.matrix.android.sdk.api.util.MimeTypes import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt @@ -337,8 +338,7 @@ class MessageItemFactory @Inject constructor( eventId = informationData.eventId, filename = messageContent.body, mimeType = messageContent.mimeType, - url = messageContent.videoInfo?.thumbnailFile?.url - ?: messageContent.videoInfo?.thumbnailUrl, + url = messageContent.videoInfo?.getThumbnailUrl(), elementToDecrypt = messageContent.videoInfo?.thumbnailFile?.toElementToDecrypt(), height = messageContent.videoInfo?.height, maxHeight = maxHeight, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/image/ImageContentRendererFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/image/ImageContentRendererFactory.kt index 7ff184f664..2ad58df3b8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/image/ImageContentRendererFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/image/ImageContentRendererFactory.kt @@ -23,6 +23,7 @@ import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.message.MessageImageContent import org.matrix.android.sdk.api.session.room.model.message.MessageVideoContent import org.matrix.android.sdk.api.session.room.model.message.getFileUrl +import org.matrix.android.sdk.api.session.room.model.message.getThumbnailUrl import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt @@ -45,15 +46,16 @@ fun TimelineEvent.buildImageContentRendererData(maxHeight: Int): ImageContentRen } root.isVideoMessage() -> root.getClearContent().toModel() ?.let { messageVideoContent -> + val videoInfo = messageVideoContent.videoInfo ImageContentRenderer.Data( eventId = eventId, filename = messageVideoContent.body, - mimeType = messageVideoContent.mimeType, - url = messageVideoContent.getFileUrl(), - elementToDecrypt = messageVideoContent.encryptedFileInfo?.toElementToDecrypt(), - height = messageVideoContent.videoInfo?.height, + mimeType = videoInfo?.thumbnailInfo?.mimeType, + url = videoInfo?.getThumbnailUrl(), + elementToDecrypt = videoInfo?.thumbnailFile?.toElementToDecrypt(), + height = videoInfo?.thumbnailInfo?.height, maxHeight = maxHeight, - width = messageVideoContent.videoInfo?.width, + width = videoInfo?.thumbnailInfo?.width, maxWidth = maxHeight * 2, allowNonMxcUrls = false ) diff --git a/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt b/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt index 976f13df58..fc6d5a1f22 100644 --- a/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt +++ b/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt @@ -30,6 +30,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageImageContent import org.matrix.android.sdk.api.session.room.model.message.MessageVideoContent import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent import org.matrix.android.sdk.api.session.room.model.message.getFileUrl +import org.matrix.android.sdk.api.session.room.model.message.getThumbnailUrl import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.util.MimeTypes import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt @@ -78,8 +79,7 @@ class RoomEventsAttachmentProvider( eventId = it.eventId, filename = content.body, mimeType = content.mimeType, - url = content.videoInfo?.thumbnailFile?.url - ?: content.videoInfo?.thumbnailUrl, + url = content.videoInfo?.getThumbnailUrl(), elementToDecrypt = content.videoInfo?.thumbnailFile?.toElementToDecrypt(), height = content.videoInfo?.height, maxHeight = -1, @@ -102,8 +102,7 @@ class RoomEventsAttachmentProvider( data = data, thumbnail = AttachmentInfo.Image( uid = it.eventId, - url = content.videoInfo?.thumbnailFile?.url - ?: content.videoInfo?.thumbnailUrl ?: "", + url = content.videoInfo?.getThumbnailUrl() ?: "", data = thumbnailData ) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt index fe6dc86165..a7f7dbfe98 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt @@ -50,6 +50,7 @@ import im.vector.app.features.roomprofile.uploads.RoomUploadsViewState import org.matrix.android.sdk.api.session.room.model.message.MessageImageContent import org.matrix.android.sdk.api.session.room.model.message.MessageVideoContent import org.matrix.android.sdk.api.session.room.model.message.getFileUrl +import org.matrix.android.sdk.api.session.room.model.message.getThumbnailUrl import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt import javax.inject.Inject @@ -141,8 +142,7 @@ class RoomUploadsMediaFragment @Inject constructor( eventId = it.eventId, filename = content.body, mimeType = content.mimeType, - url = content.videoInfo?.thumbnailFile?.url - ?: content.videoInfo?.thumbnailUrl, + url = content.videoInfo?.getThumbnailUrl(), elementToDecrypt = content.videoInfo?.thumbnailFile?.toElementToDecrypt(), height = content.videoInfo?.height, maxHeight = -1, diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/UploadsMediaController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/UploadsMediaController.kt index 2a77e65b9e..f8dff345bb 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/UploadsMediaController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/media/UploadsMediaController.kt @@ -30,6 +30,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageImageContent import org.matrix.android.sdk.api.session.room.model.message.MessageType import org.matrix.android.sdk.api.session.room.model.message.MessageVideoContent import org.matrix.android.sdk.api.session.room.model.message.getFileUrl +import org.matrix.android.sdk.api.session.room.model.message.getThumbnailUrl import org.matrix.android.sdk.api.session.room.uploads.UploadEvent import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt import javax.inject.Inject @@ -131,7 +132,7 @@ class UploadsMediaController @Inject constructor( eventId = eventId, filename = messageContent.body, mimeType = messageContent.mimeType, - url = messageContent.videoInfo?.thumbnailFile?.url ?: messageContent.videoInfo?.thumbnailUrl, + url = messageContent.videoInfo?.getThumbnailUrl(), elementToDecrypt = messageContent.videoInfo?.thumbnailFile?.toElementToDecrypt(), height = messageContent.videoInfo?.height, maxHeight = itemSize,