flattening some of the onNotifiableEventReceived branches to simplify the chain
This commit is contained in:
parent
ef348c24a0
commit
9009606e86
|
@ -107,7 +107,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
}
|
}
|
||||||
synchronized(queuedEvents) {
|
synchronized(queuedEvents) {
|
||||||
val existing = queuedEvents.findExistingById(notifiableEvent)
|
val existing = queuedEvents.findExistingById(notifiableEvent)
|
||||||
if (existing != null) {
|
val edited = queuedEvents.findEdited(notifiableEvent)
|
||||||
|
when {
|
||||||
|
existing != null -> {
|
||||||
if (existing.canBeReplaced) {
|
if (existing.canBeReplaced) {
|
||||||
// Use the event coming from the event stream as it may contains more info than
|
// Use the event coming from the event stream as it may contains more info than
|
||||||
// the fcm one (like type/content/clear text) (e.g when an encrypted message from
|
// the fcm one (like type/content/clear text) (e.g when an encrypted message from
|
||||||
|
@ -121,30 +123,22 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
} else {
|
} else {
|
||||||
// keep the existing one, do not replace
|
// keep the existing one, do not replace
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Check if this is an edit
|
|
||||||
if (notifiableEvent.editedEventId != null) {
|
|
||||||
// This is an edition
|
|
||||||
val eventBeforeEdition = queuedEvents.findEdited(notifiableEvent)
|
|
||||||
if (eventBeforeEdition != null) {
|
|
||||||
// Replace the existing notification with the new content
|
|
||||||
queuedEvents.replace(replace = eventBeforeEdition, with = notifiableEvent)
|
|
||||||
} else {
|
|
||||||
// Ignore an edit of a not displayed event in the notification drawer
|
|
||||||
}
|
}
|
||||||
} else {
|
edited != null -> {
|
||||||
// Not an edit
|
// Replace the existing notification with the new content
|
||||||
if (seenEventIds.contains(notifiableEvent.eventId)) {
|
queuedEvents.replace(replace = edited, with = notifiableEvent)
|
||||||
|
}
|
||||||
|
seenEventIds.contains(notifiableEvent.eventId) -> {
|
||||||
// we've already seen the event, lets skip
|
// we've already seen the event, lets skip
|
||||||
Timber.d("onNotifiableEventReceived(): skipping event, already seen")
|
Timber.d("onNotifiableEventReceived(): skipping event, already seen")
|
||||||
} else {
|
}
|
||||||
|
else -> {
|
||||||
seenEventIds.put(notifiableEvent.eventId)
|
seenEventIds.put(notifiableEvent.eventId)
|
||||||
queuedEvents.add(notifiableEvent)
|
queuedEvents.add(notifiableEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun updateEvents(action: (NotificationEventQueue) -> Unit) {
|
fun updateEvents(action: (NotificationEventQueue) -> Unit) {
|
||||||
synchronized(queuedEvents) {
|
synchronized(queuedEvents) {
|
||||||
|
|
|
@ -66,9 +66,10 @@ class NotificationEventQueue(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findEdited(notifiableEvent: NotifiableEvent): NotifiableEvent? {
|
fun findEdited(notifiableEvent: NotifiableEvent): NotifiableEvent? {
|
||||||
return queue.firstOrNull {
|
return notifiableEvent.editedEventId?.let { editedId ->
|
||||||
it.eventId == notifiableEvent.editedEventId ||
|
queue.firstOrNull {
|
||||||
it.editedEventId == notifiableEvent.editedEventId // or edition of an edition
|
it.eventId == editedId || it.editedEventId == editedId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue