Prune redacted events which are not explicitly restricted
This commit is contained in:
parent
eb12b1c99b
commit
0209cc4969
|
@ -61,25 +61,19 @@ internal class RedactionEventProcessor @Inject constructor() : EventInsertLivePr
|
||||||
val isLocalEcho = LocalEcho.isLocalEchoId(redactionEvent.eventId ?: "")
|
val isLocalEcho = LocalEcho.isLocalEchoId(redactionEvent.eventId ?: "")
|
||||||
Timber.v("Redact event for ${redactionEvent.redacts} localEcho=$isLocalEcho")
|
Timber.v("Redact event for ${redactionEvent.redacts} localEcho=$isLocalEcho")
|
||||||
|
|
||||||
val eventToPrune = EventEntity.where(realm, eventId = redactionEvent.redacts).findFirst()
|
val eventToPrune = EventEntity.where(realm, eventId = redactionEvent.redacts).findFirst() ?: return
|
||||||
?: return
|
|
||||||
|
|
||||||
val typeToPrune = eventToPrune.type
|
val typeToPrune = eventToPrune.type
|
||||||
val stateKey = eventToPrune.stateKey
|
val stateKey = eventToPrune.stateKey
|
||||||
val allowedKeys = computeAllowedKeys(typeToPrune)
|
val allowedKeys = computeAllowedKeys(typeToPrune)
|
||||||
if (allowedKeys.isNotEmpty()) {
|
when {
|
||||||
|
allowedKeys.isNotEmpty() -> {
|
||||||
val prunedContent = ContentMapper.map(eventToPrune.content)?.filterKeys { key -> allowedKeys.contains(key) }
|
val prunedContent = ContentMapper.map(eventToPrune.content)?.filterKeys { key -> allowedKeys.contains(key) }
|
||||||
eventToPrune.content = ContentMapper.map(prunedContent)
|
eventToPrune.content = ContentMapper.map(prunedContent)
|
||||||
} else {
|
}
|
||||||
when (typeToPrune) {
|
canPruneEventType(typeToPrune) -> {
|
||||||
EventType.ENCRYPTED,
|
|
||||||
EventType.MESSAGE,
|
|
||||||
in EventType.STATE_ROOM_BEACON_INFO.values,
|
|
||||||
in EventType.BEACON_LOCATION_DATA.values,
|
|
||||||
in EventType.POLL_START.values -> {
|
|
||||||
Timber.d("REDACTION for message ${eventToPrune.eventId}")
|
Timber.d("REDACTION for message ${eventToPrune.eventId}")
|
||||||
val unsignedData = EventMapper.map(eventToPrune).unsignedData
|
val unsignedData = EventMapper.map(eventToPrune).unsignedData ?: UnsignedData(null, null)
|
||||||
?: UnsignedData(null, null)
|
|
||||||
|
|
||||||
// was this event a m.replace
|
// was this event a m.replace
|
||||||
// val contentModel = ContentMapper.map(eventToPrune.content)?.toModel<MessageContent>()
|
// val contentModel = ContentMapper.map(eventToPrune.content)?.toModel<MessageContent>()
|
||||||
|
@ -88,8 +82,6 @@ internal class RedactionEventProcessor @Inject constructor() : EventInsertLivePr
|
||||||
// }
|
// }
|
||||||
|
|
||||||
val modified = unsignedData.copy(redactedEvent = redactionEvent)
|
val modified = unsignedData.copy(redactedEvent = redactionEvent)
|
||||||
// Deleting the content of a thread message will result to delete the thread relation, however threads are now dynamic
|
|
||||||
// so there is not much of a problem
|
|
||||||
eventToPrune.content = ContentMapper.map(emptyMap())
|
eventToPrune.content = ContentMapper.map(emptyMap())
|
||||||
eventToPrune.unsignedData = MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(modified)
|
eventToPrune.unsignedData = MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(modified)
|
||||||
eventToPrune.decryptionResultJson = null
|
eventToPrune.decryptionResultJson = null
|
||||||
|
@ -97,10 +89,6 @@ internal class RedactionEventProcessor @Inject constructor() : EventInsertLivePr
|
||||||
|
|
||||||
handleTimelineThreadSummaryIfNeeded(realm, eventToPrune, isLocalEcho)
|
handleTimelineThreadSummaryIfNeeded(realm, eventToPrune, isLocalEcho)
|
||||||
}
|
}
|
||||||
// EventType.REACTION -> {
|
|
||||||
// eventRelationsAggregationUpdater.handleReactionRedact(eventToPrune, realm, userId)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (typeToPrune == EventType.STATE_ROOM_MEMBER && stateKey != null) {
|
if (typeToPrune == EventType.STATE_ROOM_MEMBER && stateKey != null) {
|
||||||
TimelineEventEntity.findWithSenderMembershipEvent(realm, eventToPrune.eventId).forEach {
|
TimelineEventEntity.findWithSenderMembershipEvent(realm, eventToPrune.eventId).forEach {
|
||||||
|
@ -167,4 +155,34 @@ internal class RedactionEventProcessor @Inject constructor() : EventInsertLivePr
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun canPruneEventType(eventType: String): Boolean {
|
||||||
|
return when {
|
||||||
|
EventType.isCallEvent(eventType) -> false
|
||||||
|
EventType.isVerificationEvent(eventType) -> false
|
||||||
|
eventType == EventType.ROOM_KEY ||
|
||||||
|
eventType == EventType.STATE_ROOM_WIDGET_LEGACY ||
|
||||||
|
eventType == EventType.STATE_ROOM_WIDGET ||
|
||||||
|
eventType == EventType.STATE_ROOM_NAME ||
|
||||||
|
eventType == EventType.STATE_ROOM_TOPIC ||
|
||||||
|
eventType == EventType.STATE_ROOM_AVATAR ||
|
||||||
|
eventType == EventType.STATE_ROOM_THIRD_PARTY_INVITE ||
|
||||||
|
eventType == EventType.STATE_ROOM_GUEST_ACCESS ||
|
||||||
|
eventType == EventType.STATE_SPACE_CHILD ||
|
||||||
|
eventType == EventType.STATE_SPACE_PARENT ||
|
||||||
|
eventType == EventType.STATE_ROOM_TOMBSTONE ||
|
||||||
|
eventType == EventType.STATE_ROOM_HISTORY_VISIBILITY ||
|
||||||
|
eventType == EventType.STATE_ROOM_RELATED_GROUPS ||
|
||||||
|
eventType == EventType.STATE_ROOM_PINNED_EVENT ||
|
||||||
|
eventType == EventType.STATE_ROOM_ENCRYPTION ||
|
||||||
|
eventType == EventType.STATE_ROOM_SERVER_ACL ||
|
||||||
|
eventType == EventType.ROOM_KEY_REQUEST ||
|
||||||
|
eventType == EventType.FORWARDED_ROOM_KEY ||
|
||||||
|
eventType in EventType.ROOM_KEY_WITHHELD.values ||
|
||||||
|
eventType == EventType.REQUEST_SECRET ||
|
||||||
|
eventType == EventType.SEND_SECRET ||
|
||||||
|
eventType == EventType.REACTION -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue