flattening some of the onNotifiableEventReceived branches to simplify the chain
This commit is contained in:
parent
ef348c24a0
commit
9009606e86
|
@ -107,40 +107,34 @@ 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)
|
||||||
if (existing.canBeReplaced) {
|
when {
|
||||||
// Use the event coming from the event stream as it may contains more info than
|
existing != null -> {
|
||||||
// the fcm one (like type/content/clear text) (e.g when an encrypted message from
|
if (existing.canBeReplaced) {
|
||||||
// FCM should be update with clear text after a sync)
|
// Use the event coming from the event stream as it may contains more info than
|
||||||
// In this case the message has already been notified, and might have done some noise
|
// the fcm one (like type/content/clear text) (e.g when an encrypted message from
|
||||||
// So we want the notification to be updated even if it has already been displayed
|
// FCM should be update with clear text after a sync)
|
||||||
// Use setOnlyAlertOnce to ensure update notification does not interfere with sound
|
// In this case the message has already been notified, and might have done some noise
|
||||||
// from first notify invocation as outlined in:
|
// So we want the notification to be updated even if it has already been displayed
|
||||||
// https://developer.android.com/training/notify-user/build-notification#Updating
|
// Use setOnlyAlertOnce to ensure update notification does not interfere with sound
|
||||||
queuedEvents.replace(replace = existing, with = notifiableEvent)
|
// from first notify invocation as outlined in:
|
||||||
} else {
|
// https://developer.android.com/training/notify-user/build-notification#Updating
|
||||||
// keep the existing one, do not replace
|
queuedEvents.replace(replace = existing, with = notifiableEvent)
|
||||||
|
} else {
|
||||||
|
// keep the existing one, do not replace
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
edited != null -> {
|
||||||
// Check if this is an edit
|
// Replace the existing notification with the new content
|
||||||
if (notifiableEvent.editedEventId != null) {
|
queuedEvents.replace(replace = edited, with = notifiableEvent)
|
||||||
// This is an edition
|
}
|
||||||
val eventBeforeEdition = queuedEvents.findEdited(notifiableEvent)
|
seenEventIds.contains(notifiableEvent.eventId) -> {
|
||||||
if (eventBeforeEdition != null) {
|
// we've already seen the event, lets skip
|
||||||
// Replace the existing notification with the new content
|
Timber.d("onNotifiableEventReceived(): skipping event, already seen")
|
||||||
queuedEvents.replace(replace = eventBeforeEdition, with = notifiableEvent)
|
}
|
||||||
} else {
|
else -> {
|
||||||
// Ignore an edit of a not displayed event in the notification drawer
|
seenEventIds.put(notifiableEvent.eventId)
|
||||||
}
|
queuedEvents.add(notifiableEvent)
|
||||||
} else {
|
|
||||||
// Not an edit
|
|
||||||
if (seenEventIds.contains(notifiableEvent.eventId)) {
|
|
||||||
// we've already seen the event, lets skip
|
|
||||||
Timber.d("onNotifiableEventReceived(): skipping event, already seen")
|
|
||||||
} else {
|
|
||||||
seenEventIds.put(notifiableEvent.eventId)
|
|
||||||
queuedEvents.add(notifiableEvent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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