From d3dc0afd07e09c9e2e223461cf3b4fe27b188de8 Mon Sep 17 00:00:00 2001 From: nmscode <105442557+nmscode@users.noreply.github.com> Date: Fri, 14 Oct 2022 00:03:22 -0400 Subject: [PATCH] Update MessageItemFactory.kt --- .../timeline/factory/MessageItemFactory.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 38e2d1a49c4..f514ad4af65 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -16,6 +16,9 @@ package im.vector.app.features.home.room.detail.timeline.factory +import android.graphics.BitmapFactory +import android.graphics.ImageDecoder +import android.graphics.drawable.AnimatedImageDrawable import android.net.Uri import android.text.Spannable import android.text.SpannableStringBuilder @@ -120,6 +123,7 @@ import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent import org.matrix.android.sdk.api.settings.LightweightSettingsStorage import org.matrix.android.sdk.api.util.MimeTypes import timber.log.Timber +import java.nio.file.Files import javax.inject.Inject class MessageItemFactory @Inject constructor( @@ -162,16 +166,29 @@ class MessageItemFactory @Inject constructor( private val textRenderer by lazy { textRendererFactory.create(roomId) } + suspend fun decryptEmote(raw: Map): Map { val final = mutableMapOf() - Timber.v("hell"+raw.toString()) + //Timber.v("hell"+raw.toString()) for ((key, value) in raw) { - val file=(session.fileService().downloadFile( + var file=(session.fileService().downloadFile( fileName = key, mimeType = "image/*", url = value.url, elementToDecrypt = value.toElementToDecrypt() )) + val source=ImageDecoder.createSource(file) + val drawable = ImageDecoder.decodeDrawable(source) + if (drawable is AnimatedImageDrawable) { + file=(session.fileService().downloadFile( + fileName = key, + mimeType = "image/gif", + url = value.url, + elementToDecrypt = value.toElementToDecrypt() + )) + } + + //Timber.v("hello "+MimeTypeMap.getFileExtensionFromUrl(file.toString())) final[":" + key + ":"] = "" //Timber.v("emote:",final[":" + key + ":"]) }