From a187e0ec33d1d461e76db977900a8920be967759 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Thu, 16 Dec 2021 22:03:42 +0200 Subject: [PATCH] Enhance thread awareness to recognise the type of messages that are not able to be send as a reply such as images, videos, audios, stickers --- build.gradle | 2 +- .../handler/room/ThreadsAwarenessHandler.kt | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index f057d234e5..433ca8bc9d 100644 --- a/build.gradle +++ b/build.gradle @@ -154,7 +154,7 @@ project(":diff-match-patch") { // Global configurations across all modules ext { - isThreadingEnabled = true + isThreadingEnabled = false } //project(":matrix-sdk-android") { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt index 767a967522..30876c21da 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt @@ -27,6 +27,7 @@ import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.message.MessageFormat import org.matrix.android.sdk.api.session.room.model.message.MessageRelationContent import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent +import org.matrix.android.sdk.api.session.room.model.message.MessageType import org.matrix.android.sdk.api.session.room.send.SendState import org.matrix.android.sdk.api.session.sync.model.SyncResponse import org.matrix.android.sdk.api.util.JsonDict @@ -43,6 +44,7 @@ import org.matrix.android.sdk.internal.session.permalinks.PermalinkFactory import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory import org.matrix.android.sdk.internal.session.room.timeline.GetEventTask import org.matrix.android.sdk.internal.util.awaitTransaction +import timber.log.Timber import javax.inject.Inject /** @@ -84,7 +86,7 @@ internal class ThreadsAwarenessHandler @Inject constructor( if (eventList.isNullOrEmpty()) return val threadsToFetch = emptyMap().toMutableMap() - Realm.getInstance(monarchy.realmConfiguration).use { realm -> + Realm.getInstance(monarchy.realmConfiguration).use { realm -> eventList.asSequence() .filter { isThreadEvent(it) && it.roomId != null @@ -176,11 +178,29 @@ internal class ThreadsAwarenessHandler @Inject constructor( if (!isThreadEvent(event)) return null val rootThreadEventId = getRootThreadEventId(event) ?: return null val payload = decryptedResult?.toMutableMap() ?: return null - val body = getValueFromPayload(payload, "body") ?: return null + var body = getValueFromPayload(payload, "body") ?: return null val msgType = getValueFromPayload(payload, "msgtype") ?: return null val rootThreadEvent = getEventFromDB(realm, rootThreadEventId) ?: return null val rootThreadEventSenderId = rootThreadEvent.senderId ?: return null + // Check the event type + when (msgType) { + MessageType.MSGTYPE_STICKER_LOCAL -> { + body = "sent a sticker from within a thread" + } + MessageType.MSGTYPE_FILE -> { + body = "sent a file from within a thread" + } + MessageType.MSGTYPE_VIDEO -> { + body = "Sent a video from within a thread" + } + MessageType.MSGTYPE_IMAGE -> { + body = "sent an image from within a thread" + } + MessageType.MSGTYPE_AUDIO -> { + body = "sent an audio file from within a thread" + } + } decryptIfNeeded(rootThreadEvent, roomId) val rootThreadEventBody = getValueFromPayload(rootThreadEvent.mxDecryptionResult?.payload?.toMutableMap(), "body") @@ -197,7 +217,7 @@ internal class ThreadsAwarenessHandler @Inject constructor( body) val messageTextContent = MessageTextContent( - msgType = msgType, + msgType = "m.text", format = MessageFormat.FORMAT_MATRIX_HTML, body = body, formattedBody = replyFormatted