diff --git a/changelog.d/994.bugfix b/changelog.d/994.bugfix new file mode 100644 index 0000000000..7fe3e828a0 --- /dev/null +++ b/changelog.d/994.bugfix @@ -0,0 +1 @@ +Group fallback notification to avoid having plenty of them displayed. diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManager.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManager.kt index 318b7cbd49..f2e3240203 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManager.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManager.kt @@ -195,9 +195,9 @@ class DefaultNotificationDrawerManager @Inject constructor( /** * Clear the notifications for a single event. */ - fun clearEvent(eventId: EventId, doRender: Boolean) { + fun clearEvent(sessionId: SessionId, eventId: EventId, doRender: Boolean) { updateEvents(doRender = doRender) { - it.clearEvent(eventId) + it.clearEvent(sessionId, eventId) } } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt index 8f27d8692c..0fdef871a1 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt @@ -56,7 +56,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { defaultNotificationDrawerManager.clearMembershipNotificationForRoom(sessionId, roomId, doRender = false) } actionIds.dismissEvent -> if (eventId != null) { - defaultNotificationDrawerManager.clearEvent(eventId, doRender = false) + defaultNotificationDrawerManager.clearEvent(sessionId, eventId, doRender = false) } actionIds.markRoomRead -> if (roomId != null) { defaultNotificationDrawerManager.clearMessagesForRoom(sessionId, roomId, doRender = true) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationEventQueue.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationEventQueue.kt index 6b6730c904..8eea6a9d5a 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationEventQueue.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationEventQueue.kt @@ -135,8 +135,14 @@ data class NotificationEventQueue constructor( ) } - fun clearEvent(eventId: EventId) { - queue.removeAll { it.eventId == eventId } + fun clearEvent(sessionId: SessionId, eventId: EventId) { + val isFallback = queue.firstOrNull { it.sessionId == sessionId && it.eventId == eventId } is FallbackNotifiableEvent + if (isFallback) { + Timber.d("Removing all the fallbacks") + queue.removeAll { it.sessionId == sessionId && it is FallbackNotifiableEvent } + } else { + queue.removeAll { it.sessionId == sessionId && it.eventId == eventId } + } } fun clearMembershipNotificationForSession(sessionId: SessionId) { diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt index 03241bbdb8..713392c695 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt @@ -124,6 +124,7 @@ class NotificationRenderer @Inject constructor( } } + /* fallbackNotifications.forEach { wrapper -> when (wrapper) { is OneShotNotification.Removed -> { @@ -143,6 +144,23 @@ class NotificationRenderer @Inject constructor( } } } + */ + val removedFallback = fallbackNotifications.filterIsInstance() + val appendFallback = fallbackNotifications.filterIsInstance() + if (appendFallback.isEmpty() && removedFallback.isNotEmpty()) { + Timber.tag(loggerTag.value).d("Removing global fallback notification") + notificationDisplayer.cancelNotificationMessage( + tag = "FALLBACK", + id = notificationIdProvider.getFallbackNotificationId(currentUser.userId) + ) + } else if (appendFallback.isNotEmpty()) { + Timber.tag(loggerTag.value).d("Showing fallback notification") + notificationDisplayer.showNotificationMessage( + tag = "FALLBACK", + id = notificationIdProvider.getFallbackNotificationId(currentUser.userId), + notification = appendFallback.first().notification + ) + } // Update summary last to avoid briefly displaying it before other notifications if (summaryNotification is SummaryNotification.Update) {