Skip to content
1 change: 1 addition & 0 deletions changelog.d/8120.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Marks WebP files as Animated and allows them to play
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object MimeTypes {
const val BadJpg = "image/jpg"
const val Jpeg = "image/jpeg"
const val Gif = "image/gif"
const val Webp = "image/webp"

const val Ogg = "audio/ogg"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ class MessageItemFactory @Inject constructor(
)

val playable = messageContent.mimeType == MimeTypes.Gif
// don't show play button because detecting animated webp isn't possible via mimetype
val playableIfAutoplay = playable || messageContent.mimeType == MimeTypes.Webp

@alexmaras alexmaras Feb 22, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works to autoplay animated WebP in the timeline if autoplay is enabled. If it isn't enabled, no play button shows (because playable is false) which will prevent confusion with static WebP. Static WebP functions fine in autoplay mode still.

This workaround is fairly effective. I've added a comment to try to explain what's going on here.

Ideally I'd like to look at doing another PR to determine conclusively whether a Gif or a WebP is actually animated via headers, therefore allowing the play button to appear on animated WebP too, and take away the play button on static Gifs, but that would be a longer exercise.


return MessageImageVideoItem_()
.attributes(attributes)
Expand All @@ -549,7 +551,7 @@ class MessageItemFactory @Inject constructor(
}
}
}.apply {
if (playable && vectorPreferences.autoplayAnimatedImages()) {
if (playableIfAutoplay && vectorPreferences.autoplayAnimatedImages()) {
mode(ImageContentRenderer.Mode.ANIMATED_THUMBNAIL)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DataAttachmentRoomProvider(
return getItem(position).let {
when (it) {
is ImageContentRenderer.Data -> {
if (it.mimeType == MimeTypes.Gif) {
if (it.mimeType == MimeTypes.Gif || it.mimeType == MimeTypes.Webp) {
AttachmentInfo.AnimatedImage(
uid = it.eventId,
url = it.url ?: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ImageContentRenderer @Inject constructor(
if (mode == Mode.ANIMATED_THUMBNAIL) it
else it.dontAnimate()
}
.transform(cornerTransformation)
.optionalTransform(cornerTransformation)
.into(imageView)
}

Expand Down Expand Up @@ -167,7 +167,7 @@ class ImageContentRenderer @Inject constructor(
}

req
.fitCenter()
.optionalFitCenter()
.into(target)
}

Expand Down Expand Up @@ -211,7 +211,7 @@ class ImageContentRenderer @Inject constructor(
return false
}
})
.fitCenter()
.optionalFitCenter()
.into(imageView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RoomEventsAttachmentProvider(
allowNonMxcUrls = it.root.sendState.isSending()

)
if (content.mimeType == MimeTypes.Gif) {
if (content.mimeType == MimeTypes.Gif || content.mimeType == MimeTypes.Webp) {
AttachmentInfo.AnimatedImage(
uid = it.eventId,
url = content.url ?: "",
Expand Down