From 555f73dfa82b4881b4c102c5c354760bcfdd2171 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Mon, 30 Sep 2024 21:05:58 +0100 Subject: [PATCH] Use MSC2530 filename when loading media In the case of captioned images, the `body` of the event is the caption, and is ill suited to be a filename. Often the caption can be prohibitively long, causing the media to fail to load in some cases. Fixes: https://github.com/element-hq/element-x-android/issues/2882 Signed-off-by: Joe Groocock --- .../android/features/messages/impl/MessagesFlowNode.kt | 4 ++-- .../timeline/components/event/TimelineItemImageView.kt | 8 +++++++- .../timeline/components/event/TimelineItemVideoView.kt | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt index 12df0bc0bf..08b485b1e7 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt @@ -324,7 +324,7 @@ class MessagesFlowNode @AssistedInject constructor( is TimelineItemImageContent -> { val navTarget = NavTarget.MediaViewer( mediaInfo = MediaInfo( - name = event.content.body, + name = event.content.filename ?: event.content.body, mimeType = event.content.mimeType, formattedFileSize = event.content.formattedFileSize, fileExtension = event.content.fileExtension @@ -358,7 +358,7 @@ class MessagesFlowNode @AssistedInject constructor( is TimelineItemVideoContent -> { val navTarget = NavTarget.MediaViewer( mediaInfo = MediaInfo( - name = event.content.body, + name = event.content.filename ?: event.content.body, mimeType = event.content.mimeType, formattedFileSize = event.content.formattedFileSize, fileExtension = event.content.fileExtension diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt index af401dc56a..9f9222f458 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt @@ -81,7 +81,13 @@ fun TimelineItemImageView( modifier = Modifier .fillMaxWidth() .then(if (isLoaded) Modifier.background(Color.White) else Modifier), - model = MediaRequestData(content.preferredMediaSource, MediaRequestData.Kind.File(content.body, content.mimeType)), + model = MediaRequestData( + source = content.preferredMediaSource, + kind = MediaRequestData.Kind.File( + body = content.filename ?: content.body, + mimeType = content.mimeType, + ), + ), contentScale = ContentScale.Fit, alignment = Alignment.Center, contentDescription = description, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt index 31cb5f1607..7324d3368b 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt @@ -88,7 +88,13 @@ fun TimelineItemVideoView( modifier = Modifier .fillMaxWidth() .then(if (isLoaded) Modifier.background(Color.White) else Modifier), - model = MediaRequestData(content.thumbnailSource, MediaRequestData.Kind.File(content.body, content.mimeType)), + model = MediaRequestData( + source = content.thumbnailSource, + kind = MediaRequestData.Kind.File( + body = content.filename ?: content.body, + mimeType = content.mimeType + ) + ), contentScale = ContentScale.Fit, alignment = Alignment.Center, contentDescription = description,