Browse Source

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 <me@frebib.net>
pull/3567/head
Joe Groocock 3 weeks ago
parent
commit
555f73dfa8
No known key found for this signature in database
GPG Key ID: A5571FCDC53ADDE6
  1. 4
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt
  2. 8
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt
  3. 8
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt

4
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt

@ -324,7 +324,7 @@ class MessagesFlowNode @AssistedInject constructor( @@ -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( @@ -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

8
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt

@ -81,7 +81,13 @@ fun TimelineItemImageView( @@ -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,

8
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt

@ -88,7 +88,13 @@ fun TimelineItemVideoView( @@ -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,

Loading…
Cancel
Save