making the isRedacted event property immutable

- also makes the notifiable events sealed interfaces so that we can copy the data classes with new redacted values when it changes
This commit is contained in:
Adam Brown 2021-10-07 11:46:13 +01:00
parent 89d643a4be
commit c99dd4a615
5 changed files with 26 additions and 15 deletions

View file

@ -26,8 +26,9 @@ data class InviteNotifiableEvent(
val type: String?, val type: String?,
val timestamp: Long, val timestamp: Long,
val soundName: String?, val soundName: String?,
override var isPushGatewayEvent: Boolean = false) : NotifiableEvent { override var isPushGatewayEvent: Boolean = false,
override val isRedacted: Boolean = false
) : NotifiableEvent {
override var isRedacted: Boolean = false
override var hasBeenDisplayed = false override var hasBeenDisplayed = false
} }

View file

@ -20,14 +20,12 @@ import java.io.Serializable
/** /**
* Parent interface for all events which can be displayed as a Notification * Parent interface for all events which can be displayed as a Notification
*/ */
interface NotifiableEvent : Serializable { sealed interface NotifiableEvent : Serializable {
val eventId: String val eventId: String
val editedEventId: String? val editedEventId: String?
var noisy: Boolean var noisy: Boolean
var hasBeenDisplayed: Boolean var hasBeenDisplayed: Boolean
var isRedacted: Boolean
// Used to know if event should be replaced with the one coming from eventstream // Used to know if event should be replaced with the one coming from eventstream
var isPushGatewayEvent: Boolean var isPushGatewayEvent: Boolean
val isRedacted: Boolean
} }

View file

@ -36,12 +36,11 @@ data class NotifiableMessageEvent(
// This is used for >N notification, as the result of a smart reply // This is used for >N notification, as the result of a smart reply
val outGoingMessage: Boolean = false, val outGoingMessage: Boolean = false,
val outGoingMessageFailed: Boolean = false val outGoingMessageFailed: Boolean = false,
override var hasBeenDisplayed: Boolean = false,
override val isRedacted: Boolean = false
) : NotifiableEvent { ) : NotifiableEvent {
override var hasBeenDisplayed: Boolean = false
override var isRedacted: Boolean = false
override var isPushGatewayEvent: Boolean = false override var isPushGatewayEvent: Boolean = false
val type: String = EventType.MESSAGE val type: String = EventType.MESSAGE

View file

@ -162,9 +162,12 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
fun onEventRedacted(eventId: String) { fun onEventRedacted(eventId: String) {
synchronized(eventList) { synchronized(eventList) {
eventList.find { it.eventId == eventId }?.apply { eventList.replace(eventId) {
isRedacted = true when (it) {
hasBeenDisplayed = false is InviteNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
is NotifiableMessageEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
is SimpleNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
}
} }
} }
} }
@ -665,3 +668,11 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
private const val KEY_ALIAS_SECRET_STORAGE = "notificationMgr" private const val KEY_ALIAS_SECRET_STORAGE = "notificationMgr"
} }
} }
private fun MutableList<NotifiableEvent>.replace(eventId: String, block: (NotifiableEvent) -> NotifiableEvent) {
val indexToReplace = indexOfFirst { it.eventId == eventId }
if (indexToReplace == -1) {
return
}
set(indexToReplace, block(get(indexToReplace)))
}

View file

@ -25,8 +25,10 @@ data class SimpleNotifiableEvent(
val type: String?, val type: String?,
val timestamp: Long, val timestamp: Long,
val soundName: String?, val soundName: String?,
override var isPushGatewayEvent: Boolean = false) : NotifiableEvent { override var isPushGatewayEvent: Boolean = false,
override val isRedacted: Boolean = false
) : NotifiableEvent {
override var hasBeenDisplayed: Boolean = false override var hasBeenDisplayed: Boolean = false
override var isRedacted: Boolean = false
} }