Browse Source

[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>
pull/2162/head
Marco Antonio Alvarez 9 months ago committed by GitHub
parent
commit
a81fdddab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      changelog.d/1949.bugfix
  2. 26
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt
  3. 9
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemStickerContent.kt

1
changelog.d/1949.bugfix

@ -0,0 +1 @@ @@ -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

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

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

9
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemStickerContent.kt

@ -16,7 +16,6 @@ @@ -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( @@ -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
}

Loading…
Cancel
Save