Fix redacted event format on room overview.

Fixes #758
This commit is contained in:
onurays 2020-02-26 16:51:01 +03:00
parent b7cf7e06a7
commit 04726a1ace
4 changed files with 30 additions and 26 deletions

View file

@ -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 🗣:
-

View file

@ -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<EventSharedAction> {
val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
?: timelineEvent.root.getClearContent().toModel()

View file

@ -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)

View file

@ -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)
}
}
}
}
}