flattening some of the onNotifiableEventReceived branches to simplify the chain

This commit is contained in:
Adam Brown 2021-11-03 12:24:16 +00:00
parent ef348c24a0
commit 9009606e86
2 changed files with 31 additions and 36 deletions

View File

@ -107,7 +107,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
}
synchronized(queuedEvents) {
val existing = queuedEvents.findExistingById(notifiableEvent)
if (existing != null) {
val edited = queuedEvents.findEdited(notifiableEvent)
when {
existing != null -> {
if (existing.canBeReplaced) {
// 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
@ -121,30 +123,22 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
} else {
// 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 {
// Not an edit
if (seenEventIds.contains(notifiableEvent.eventId)) {
edited != null -> {
// Replace the existing notification with the new content
queuedEvents.replace(replace = edited, with = notifiableEvent)
}
seenEventIds.contains(notifiableEvent.eventId) -> {
// we've already seen the event, lets skip
Timber.d("onNotifiableEventReceived(): skipping event, already seen")
} else {
}
else -> {
seenEventIds.put(notifiableEvent.eventId)
queuedEvents.add(notifiableEvent)
}
}
}
}
}
fun updateEvents(action: (NotificationEventQueue) -> Unit) {
synchronized(queuedEvents) {

View File

@ -66,9 +66,10 @@ class NotificationEventQueue(
}
fun findEdited(notifiableEvent: NotifiableEvent): NotifiableEvent? {
return queue.firstOrNull {
it.eventId == notifiableEvent.editedEventId ||
it.editedEventId == notifiableEvent.editedEventId // or edition of an edition
return notifiableEvent.editedEventId?.let { editedId ->
queue.firstOrNull {
it.eventId == editedId || it.editedEventId == editedId
}
}
}