From 4560d748d3837f39aabd3a9ce5ae891401b68666 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Tue, 11 Jan 2022 17:52:14 +0200 Subject: [PATCH] Display encrypted messages in thread summary and in thread list --- .../matrix/android/sdk/api/session/events/model/Event.kt | 4 ++-- .../android/sdk/internal/database/mapper/EventMapper.kt | 2 +- .../app/features/home/room/detail/TimelineFragment.kt | 6 +++++- .../room/detail/timeline/factory/EncryptedItemFactory.kt | 7 ++++++- .../timeline/helper/MessageItemAttributesFactory.kt | 4 ++++ .../home/room/detail/timeline/item/AbsMessageItem.kt | 3 ++- .../room/threads/list/viewmodel/ThreadListController.kt | 8 ++++++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt index 7372a83873..895280732e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt @@ -197,8 +197,8 @@ data class Event( * It can be used especially for message summaries. * It will return a decrypted text message or an empty string otherwise. */ - fun getDecryptedTextSummary(): String { - val text = getDecryptedValue().orEmpty() + fun getDecryptedTextSummary(): String? { + val text = getDecryptedValue() ?: return null return when { isReply() || isQuote() -> ContentUtils.extractUsefulTextFromReply(text) isFileMessage() -> "sent a file." diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/EventMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/EventMapper.kt index 05070efe1f..3504284427 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/EventMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/EventMapper.kt @@ -113,7 +113,7 @@ internal object EventMapper { ) }, threadNotificationState = eventEntity.threadNotificationState, - threadSummaryLatestTextMessage = eventEntity.threadSummaryLatestMessage?.root?.asDomain()?.getDecryptedTextSummary().orEmpty(), + threadSummaryLatestTextMessage = eventEntity.threadSummaryLatestMessage?.root?.asDomain()?.getDecryptedTextSummary(), lastMessageTimestamp = eventEntity.threadSummaryLatestMessage?.root?.originServerTs ) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index dc5eb34e08..7f44aed15b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -1902,7 +1902,11 @@ class TimelineFragment @Inject constructor( roomDetailViewModel.handle(action) } is EncryptedEventContent -> { - roomDetailViewModel.handle(RoomDetailAction.TapOnFailedToDecrypt(informationData.eventId)) + if(isRootThreadEvent){ + onThreadSummaryClicked(informationData.eventId, isRootThreadEvent) + }else { + roomDetailViewModel.handle(RoomDetailAction.TapOnFailedToDecrypt(informationData.eventId)) + } } else -> { onThreadSummaryClicked(informationData.eventId, isRootThreadEvent) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt index 89c9c51f0c..f1ffc77a36 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt @@ -106,7 +106,12 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat } val informationData = messageInformationDataFactory.create(params) - val attributes = attributesFactory.create(event.root.content.toModel(), informationData, params.callback) + val threadDetails = if (params.isFromThreadTimeline()) null else event.root.threadDetails + val attributes = attributesFactory.create( + messageContent = event.root.content.toModel(), + informationData = informationData, + callback = params.callback, + threadDetails = threadDetails) return MessageTextItem_() .leftGuideline(avatarSizeProvider.leftGuideline) .highlighted(params.isHighlighted) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt index 8cc5ffe1ee..a2cdbec7c6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt @@ -16,6 +16,8 @@ package im.vector.app.features.home.room.detail.timeline.helper import im.vector.app.EmojiCompatFontProvider +import im.vector.app.R +import im.vector.app.core.resources.StringProvider import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController @@ -28,6 +30,7 @@ class MessageItemAttributesFactory @Inject constructor( private val avatarRenderer: AvatarRenderer, private val messageColorProvider: MessageColorProvider, private val avatarSizeProvider: AvatarSizeProvider, + private val stringProvider: StringProvider, private val emojiCompatFontProvider: EmojiCompatFontProvider) { fun create(messageContent: Any?, @@ -53,6 +56,7 @@ class MessageItemAttributesFactory @Inject constructor( threadCallback = callback, readReceiptsCallback = callback, emojiTypeFace = emojiCompatFontProvider.typeface, + decryptionErrorMessage = stringProvider.getString(R.string.encrypted_message), threadDetails = threadDetails ) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index f75df30916..33eae89e31 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -118,7 +118,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem attributes.threadDetails?.let { threadDetails -> holder.threadSummaryConstraintLayout.isVisible = threadDetails.isRootThread holder.threadSummaryCounterTextView.text = threadDetails.numberOfThreads.toString() - holder.threadSummaryInfoTextView.text = threadDetails.threadSummaryLatestTextMessage + holder.threadSummaryInfoTextView.text = threadDetails.threadSummaryLatestTextMessage ?: attributes.decryptionErrorMessage val userId = threadDetails.threadSummarySenderInfo?.userId ?: return@let val displayName = threadDetails.threadSummarySenderInfo?.displayName @@ -185,6 +185,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem val threadCallback: TimelineEventController.ThreadCallback? = null, override val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null, val emojiTypeFace: Typeface? = null, + val decryptionErrorMessage: String? = null, val threadDetails: ThreadDetails? = null ) : AbsBaseMessageItem.Attributes { diff --git a/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt b/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt index 3f69701a31..984c8e8f7e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt @@ -17,8 +17,10 @@ package im.vector.app.features.home.room.threads.list.viewmodel import com.airbnb.epoxy.EpoxyController +import im.vector.app.R import im.vector.app.core.date.DateFormatKind import im.vector.app.core.date.VectorDateFormatter +import im.vector.app.core.resources.StringProvider import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.threads.list.model.threadList import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent @@ -28,6 +30,7 @@ import javax.inject.Inject class ThreadListController @Inject constructor( private val avatarRenderer: AvatarRenderer, + private val stringProvider: StringProvider, private val dateFormatter: VectorDateFormatter ) : EpoxyController() { @@ -56,6 +59,7 @@ class ThreadListController @Inject constructor( } ?.forEach { timelineEvent -> val date = dateFormatter.format(timelineEvent.root.threadDetails?.lastMessageTimestamp, DateFormatKind.ROOM_LIST) + val decryptionErrorMessage = stringProvider.getString(R.string.encrypted_message) threadList { id(timelineEvent.eventId) avatarRenderer(host.avatarRenderer) @@ -64,8 +68,8 @@ class ThreadListController @Inject constructor( date(date) rootMessageDeleted(timelineEvent.root.isRedacted()) threadNotificationState(timelineEvent.root.threadDetails?.threadNotificationState ?: ThreadNotificationState.NO_NEW_MESSAGE) - rootMessage(timelineEvent.root.getDecryptedTextSummary()) - lastMessage(timelineEvent.root.threadDetails?.threadSummaryLatestTextMessage.orEmpty()) + rootMessage(timelineEvent.root.getDecryptedTextSummary() ?: decryptionErrorMessage) + lastMessage(timelineEvent.root.threadDetails?.threadSummaryLatestTextMessage ?: decryptionErrorMessage) lastMessageCounter(timelineEvent.root.threadDetails?.numberOfThreads.toString()) lastMessageMatrixItem(timelineEvent.root.threadDetails?.threadSummarySenderInfo?.toMatrixItem()) itemClickListener {