Simplify logic of the use case to check if event can be redacted

This commit is contained in:
Maxime NATUREL 2022-07-18 14:43:42 +02:00
parent 667b30f145
commit 99fc4b4a21

View File

@ -29,10 +29,9 @@ class CheckIfCanRedactEventUseCase @Inject constructor(
// Only some event types are supported for the moment
val canRedactEventTypes = listOf(EventType.MESSAGE, EventType.STICKER) +
EventType.POLL_START + EventType.STATE_ROOM_BEACON_INFO
if (event.root.getClearType() !in canRedactEventTypes) return false
// Message sent by the current user can always be redacted
if (event.root.senderId == activeSessionHolder.getActiveSession().myUserId) return true
// Check permission for messages sent by other users
return actionPermissions.canRedact
return event.root.getClearType() in canRedactEventTypes &&
// Message sent by the current user can always be redacted, else check permission for messages sent by other users
(event.root.senderId == activeSessionHolder.getActiveSession().myUserId || actionPermissions.canRedact)
}
}