From 04726a1ace63db2beef0430aadfccb760e9aaccd Mon Sep 17 00:00:00 2001 From: onurays Date: Wed, 26 Feb 2020 16:51:01 +0300 Subject: [PATCH] Fix redacted event format on room overview. Fixes #758 --- CHANGES.md | 1 + .../action/MessageActionsViewModel.kt | 27 +------------------ .../format/DisplayableEventFormatter.kt | 4 +++ .../timeline/format/NoticeEventFormatter.kt | 24 +++++++++++++++++ 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0738286678..5524769469 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ Bugfix 🐛: - Fix some invitation handling issues (#1013) - New direct chat: selecting a participant sometimes results in two breadcrumbs (#1022) - New direct chat: selecting several participants was not adding the room to the direct chats list + - Room overview shows deleted messages as “Encrypted message” (#758) Translations 🗣: - diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index a36215007d..edbf4b1a71 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -169,7 +169,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted private fun computeMessageBody(timelineEvent: TimelineEvent): CharSequence { if (timelineEvent.root.isRedacted()) { - return getRedactionReason(timelineEvent) + return noticeEventFormatter.getRedactionReason(timelineEvent.root) } return when (timelineEvent.root.getClearType()) { @@ -204,31 +204,6 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted } ?: "" } - private fun getRedactionReason(timelineEvent: TimelineEvent): String { - return (timelineEvent - .root - .unsignedData - ?.redactedEvent - ?.content - ?.get("reason") as? String) - ?.takeIf { it.isNotBlank() } - .let { reason -> - if (reason == null) { - if (timelineEvent.root.isRedactedBySameUser()) { - stringProvider.getString(R.string.event_redacted_by_user_reason) - } else { - stringProvider.getString(R.string.event_redacted_by_admin_reason) - } - } else { - if (timelineEvent.root.isRedactedBySameUser()) { - stringProvider.getString(R.string.event_redacted_by_user_reason_with_reason, reason) - } else { - stringProvider.getString(R.string.event_redacted_by_admin_reason_with_reason, reason) - } - } - } - } - private fun actionsForEvent(timelineEvent: TimelineEvent): List { val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel() ?: timelineEvent.root.getClearContent().toModel() diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt index 294429368a..b214640ef3 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt @@ -36,6 +36,10 @@ class DisplayableEventFormatter @Inject constructor( ) { fun format(timelineEvent: TimelineEvent, appendAuthor: Boolean): CharSequence { + if (timelineEvent.root.isRedacted()) { + return noticeEventFormatter.getRedactionReason(timelineEvent.root) + } + if (timelineEvent.root.isEncrypted() && timelineEvent.root.mxDecryptionResult == null) { return stringProvider.getString(R.string.encrypted_message) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 8d70279fce..5453ba8403 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -317,4 +317,28 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active else -> null } } + + fun getRedactionReason(event: Event): String { + return (event + .unsignedData + ?.redactedEvent + ?.content + ?.get("reason") as? String) + ?.takeIf { it.isNotBlank() } + .let { reason -> + if (reason == null) { + if (event.isRedactedBySameUser()) { + sp.getString(R.string.event_redacted_by_user_reason) + } else { + sp.getString(R.string.event_redacted_by_admin_reason) + } + } else { + if (event.isRedactedBySameUser()) { + sp.getString(R.string.event_redacted_by_user_reason_with_reason, reason) + } else { + sp.getString(R.string.event_redacted_by_admin_reason_with_reason, reason) + } + } + } + } }