From 1b413934b51b05c84cabed2a6257df78503cdc40 Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 13 Feb 2020 16:42:13 +0300 Subject: [PATCH] Set redaction reason as message body. --- .../action/MessageActionsViewModel.kt | 46 ++++++++++++++----- vector/src/main/res/values/strings_riotX.xml | 3 ++ 2 files changed, 38 insertions(+), 11 deletions(-) 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 5a52907bfa..e7c8cfec54 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 @@ -171,18 +171,23 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted return when (timelineEvent.root.getClearType()) { EventType.MESSAGE, EventType.STICKER -> { - val messageContent: MessageContent? = timelineEvent.getLastMessageContent() - if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) { - val html = messageContent.formattedBody - ?.takeIf { it.isNotBlank() } - ?.let { htmlCompressor.compress(it) } - ?: messageContent.body + when (timelineEvent.root.isRedacted()) { + true -> getRedactionReason(timelineEvent) + false -> { + val messageContent: MessageContent? = timelineEvent.getLastMessageContent() + if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) { + val html = messageContent.formattedBody + ?.takeIf { it.isNotBlank() } + ?.let { htmlCompressor.compress(it) } + ?: messageContent.body - eventHtmlRenderer.get().render(html) - } else if (messageContent is MessageVerificationRequestContent) { - stringProvider.getString(R.string.verification_request) - } else { - messageContent?.body + eventHtmlRenderer.get().render(html) + } else if (messageContent is MessageVerificationRequestContent) { + stringProvider.getString(R.string.verification_request) + } else { + messageContent?.body + } + } } } EventType.STATE_ROOM_NAME, @@ -200,6 +205,25 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted } ?: "" } + private fun getRedactionReason(timelineEvent: TimelineEvent) = + (timelineEvent + .root + .unsignedData + ?.redactedEvent + ?.content + ?.get("reason") as? String) + ?.takeIf { it.isNotBlank() } + ?.let { reason -> + stringProvider.getString( + (R.string.event_redacted_by_user_reason_with_reason + .takeIf { timelineEvent.root.senderId == session.myUserId } + ?: R.string.event_redacted_by_admin_reason_with_reason), reason + ) + } ?: stringProvider.getString( + R.string.event_redacted_by_user_reason + .takeIf { timelineEvent.root.senderId == session.myUserId } + ?: R.string.event_redacted_by_admin_reason_with_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/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 75790348de..ee70ac91ff 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -33,6 +33,9 @@ Are you sure you wish to remove (delete) this event? Note that if you delete a room name or topic change, it could undo the change. Include a reason Reason for redacting + + Event deleted by user, reason: %1$s + Event moderated by room admin, reason: %1$s