Set redaction reason as message body.

This commit is contained in:
onurays 2020-02-13 16:42:13 +03:00
parent 8a3e93ae96
commit 1b413934b5
2 changed files with 38 additions and 11 deletions

View File

@ -171,18 +171,23 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
return when (timelineEvent.root.getClearType()) { return when (timelineEvent.root.getClearType()) {
EventType.MESSAGE, EventType.MESSAGE,
EventType.STICKER -> { EventType.STICKER -> {
val messageContent: MessageContent? = timelineEvent.getLastMessageContent() when (timelineEvent.root.isRedacted()) {
if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) { true -> getRedactionReason(timelineEvent)
val html = messageContent.formattedBody false -> {
?.takeIf { it.isNotBlank() } val messageContent: MessageContent? = timelineEvent.getLastMessageContent()
?.let { htmlCompressor.compress(it) } if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) {
?: messageContent.body val html = messageContent.formattedBody
?.takeIf { it.isNotBlank() }
?.let { htmlCompressor.compress(it) }
?: messageContent.body
eventHtmlRenderer.get().render(html) eventHtmlRenderer.get().render(html)
} else if (messageContent is MessageVerificationRequestContent) { } else if (messageContent is MessageVerificationRequestContent) {
stringProvider.getString(R.string.verification_request) stringProvider.getString(R.string.verification_request)
} else { } else {
messageContent?.body messageContent?.body
}
}
} }
} }
EventType.STATE_ROOM_NAME, 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<EventSharedAction> { private fun actionsForEvent(timelineEvent: TimelineEvent): List<EventSharedAction> {
val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel() val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
?: timelineEvent.root.getClearContent().toModel() ?: timelineEvent.root.getClearContent().toModel()

View File

@ -33,6 +33,9 @@
<string name="delete_event_dialog_content">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.</string> <string name="delete_event_dialog_content">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.</string>
<string name="delete_event_dialog_reason_checkbox">Include a reason</string> <string name="delete_event_dialog_reason_checkbox">Include a reason</string>
<string name="delete_event_dialog_reason_hint">Reason for redacting</string> <string name="delete_event_dialog_reason_hint">Reason for redacting</string>
<string name="event_redacted_by_user_reason_with_reason">Event deleted by user, reason: %1$s</string>
<string name="event_redacted_by_admin_reason_with_reason">Event moderated by room admin, reason: %1$s</string>
<!-- END Strings added by Onuray --> <!-- END Strings added by Onuray -->