mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 09:56:00 +03:00
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:
parent
89d643a4be
commit
c99dd4a615
5 changed files with 26 additions and 15 deletions
|
@ -26,8 +26,9 @@ data class InviteNotifiableEvent(
|
|||
val type: String?,
|
||||
val timestamp: Long,
|
||||
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
|
||||
}
|
||||
|
|
|
@ -20,14 +20,12 @@ import java.io.Serializable
|
|||
/**
|
||||
* Parent interface for all events which can be displayed as a Notification
|
||||
*/
|
||||
interface NotifiableEvent : Serializable {
|
||||
sealed interface NotifiableEvent : Serializable {
|
||||
val eventId: String
|
||||
val editedEventId: String?
|
||||
var noisy: Boolean
|
||||
|
||||
var hasBeenDisplayed: Boolean
|
||||
var isRedacted: Boolean
|
||||
|
||||
// Used to know if event should be replaced with the one coming from eventstream
|
||||
var isPushGatewayEvent: Boolean
|
||||
val isRedacted: Boolean
|
||||
}
|
||||
|
|
|
@ -36,12 +36,11 @@ data class NotifiableMessageEvent(
|
|||
|
||||
// This is used for >N notification, as the result of a smart reply
|
||||
val outGoingMessage: Boolean = false,
|
||||
val outGoingMessageFailed: Boolean = false
|
||||
|
||||
val outGoingMessageFailed: Boolean = false,
|
||||
override var hasBeenDisplayed: Boolean = false,
|
||||
override val isRedacted: Boolean = false
|
||||
) : NotifiableEvent {
|
||||
|
||||
override var hasBeenDisplayed: Boolean = false
|
||||
override var isRedacted: Boolean = false
|
||||
override var isPushGatewayEvent: Boolean = false
|
||||
|
||||
val type: String = EventType.MESSAGE
|
||||
|
|
|
@ -162,9 +162,12 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
|||
|
||||
fun onEventRedacted(eventId: String) {
|
||||
synchronized(eventList) {
|
||||
eventList.find { it.eventId == eventId }?.apply {
|
||||
isRedacted = true
|
||||
hasBeenDisplayed = false
|
||||
eventList.replace(eventId) {
|
||||
when (it) {
|
||||
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 fun MutableList<NotifiableEvent>.replace(eventId: String, block: (NotifiableEvent) -> NotifiableEvent) {
|
||||
val indexToReplace = indexOfFirst { it.eventId == eventId }
|
||||
if (indexToReplace == -1) {
|
||||
return
|
||||
}
|
||||
set(indexToReplace, block(get(indexToReplace)))
|
||||
}
|
||||
|
|
|
@ -25,8 +25,10 @@ data class SimpleNotifiableEvent(
|
|||
val type: String?,
|
||||
val timestamp: Long,
|
||||
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 isRedacted: Boolean = false
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue