Merge pull request #1081 from vector-im/feature/fix_redacted_event_format
Fix redacted event format on room overview.
This commit is contained in:
commit
5e775298a7
|
@ -23,6 +23,7 @@ Bugfix 🐛:
|
||||||
- Fix some invitation handling issues (#1013)
|
- Fix some invitation handling issues (#1013)
|
||||||
- New direct chat: selecting a participant sometimes results in two breadcrumbs (#1022)
|
- 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
|
- 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 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
|
|
@ -169,7 +169,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
|
|
||||||
private fun computeMessageBody(timelineEvent: TimelineEvent): CharSequence {
|
private fun computeMessageBody(timelineEvent: TimelineEvent): CharSequence {
|
||||||
if (timelineEvent.root.isRedacted()) {
|
if (timelineEvent.root.isRedacted()) {
|
||||||
return getRedactionReason(timelineEvent)
|
return noticeEventFormatter.formatRedactedEvent(timelineEvent.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (timelineEvent.root.getClearType()) {
|
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> {
|
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()
|
||||||
|
|
|
@ -36,6 +36,10 @@ class DisplayableEventFormatter @Inject constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun format(timelineEvent: TimelineEvent, appendAuthor: Boolean): CharSequence {
|
fun format(timelineEvent: TimelineEvent, appendAuthor: Boolean): CharSequence {
|
||||||
|
if (timelineEvent.root.isRedacted()) {
|
||||||
|
return noticeEventFormatter.formatRedactedEvent(timelineEvent.root)
|
||||||
|
}
|
||||||
|
|
||||||
if (timelineEvent.root.isEncrypted()
|
if (timelineEvent.root.isEncrypted()
|
||||||
&& timelineEvent.root.mxDecryptionResult == null) {
|
&& timelineEvent.root.mxDecryptionResult == null) {
|
||||||
return stringProvider.getString(R.string.encrypted_message)
|
return stringProvider.getString(R.string.encrypted_message)
|
||||||
|
|
|
@ -317,4 +317,28 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun formatRedactedEvent(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue