[Technical] Open stickers using the thumbnail url if the main url is empty (#2157)

* Explicitely use the thumbnail url to show stickers if the content's url is an empty string

---------

Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
This commit is contained in:
Marco Antonio Alvarez
2024-01-04 09:06:30 +01:00
committed by GitHub
parent c6d109c424
commit 83e4af52b9
3 changed files with 19 additions and 17 deletions

1
changelog.d/1949.bugfix Normal file
View File

@@ -0,0 +1 @@
Make sure the media viewer tries the main url first (if not empty) then the thumbnail url and then not open if both are missing instead of failing with an error dialog

View File

@@ -255,17 +255,21 @@ class MessagesFlowNode @AssistedInject constructor(
overlay.show(navTarget)
}
is TimelineItemStickerContent -> {
val navTarget = NavTarget.MediaViewer(
mediaInfo = MediaInfo(
name = event.content.body,
mimeType = event.content.mimeType,
formattedFileSize = event.content.formattedFileSize,
fileExtension = event.content.fileExtension
),
mediaSource = event.content.mediaSource,
thumbnailSource = event.content.thumbnailSource,
)
overlay.show(navTarget)
/* Sticker may have an empty url and no thumbnail
if encrypted on certain bridges */
if (event.content.preferredMediaSource != null) {
val navTarget = NavTarget.MediaViewer(
mediaInfo = MediaInfo(
name = event.content.body,
mimeType = event.content.mimeType,
formattedFileSize = event.content.formattedFileSize,
fileExtension = event.content.fileExtension
),
mediaSource = event.content.preferredMediaSource,
thumbnailSource = event.content.thumbnailSource,
)
overlay.show(navTarget)
}
}
is TimelineItemVideoContent -> {
val navTarget = NavTarget.MediaViewer(

View File

@@ -16,7 +16,6 @@
package io.element.android.features.messages.impl.timeline.model.event
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.matrix.api.media.MediaSource
data class TimelineItemStickerContent(
@@ -33,9 +32,7 @@ data class TimelineItemStickerContent(
) : TimelineItemEventContent {
override val type: String = "TimelineItemStickerContent"
val preferredMediaSource = if (mimeType == MimeTypes.Gif) {
mediaSource
} else {
thumbnailSource ?: mediaSource
}
/* Stickers are supposed to be small images so
we allow using the mediaSource (unless the url is empty) */
val preferredMediaSource = if (mediaSource.url.isEmpty()) thumbnailSource else mediaSource
}