Merge branch 'develop' into feature/bma/noWarnings

This commit is contained in:
Benoit Marty 2023-07-21 12:17:50 +02:00 committed by GitHub
commit 5e2e03f054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
102 changed files with 1091 additions and 292 deletions

View file

@ -33,6 +33,7 @@ import io.element.android.libraries.push.api.notifications.NotificationDrawerMan
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
import io.element.android.services.appnavstate.api.AppNavigationStateService
import io.element.android.services.appnavstate.api.NavigationState
import io.element.android.services.appnavstate.api.currentSessionId
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -74,9 +75,16 @@ class DefaultNotificationDrawerManager @Inject constructor(
}
}
private var currentAppNavigationState: NavigationState? = null
private fun onAppNavigationStateChange(navigationState: NavigationState) {
when (navigationState) {
NavigationState.Root -> {}
NavigationState.Root -> {
currentAppNavigationState?.currentSessionId()?.let { sessionId ->
// User signed out, clear all notifications related to the session.
clearAllEvents(sessionId)
}
}
is NavigationState.Session -> {}
is NavigationState.Space -> {}
is NavigationState.Room -> {
@ -91,6 +99,7 @@ class DefaultNotificationDrawerManager @Inject constructor(
)
}
}
currentAppNavigationState = navigationState
}
private fun createInitialNotificationState(): NotificationState {
@ -131,12 +140,21 @@ class DefaultNotificationDrawerManager @Inject constructor(
/**
* Clear all known events and refresh the notification drawer.
*/
fun clearAllEvents(sessionId: SessionId) {
fun clearAllMessagesEvents(sessionId: SessionId) {
updateEvents {
it.clearMessagesForSession(sessionId)
}
}
/**
* Clear all notifications related to the session and refresh the notification drawer.
*/
fun clearAllEvents(sessionId: SessionId) {
updateEvents {
it.clearAllForSession(sessionId)
}
}
/**
* Should be called when the application is currently opened and showing timeline for the given roomId.
* Used to ignore events related to that room (no need to display notification) and clean any existing notification on this room.

View file

@ -52,7 +52,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
defaultNotificationDrawerManager.clearMessagesForRoom(sessionId, roomId)
}
actionIds.dismissSummary ->
defaultNotificationDrawerManager.clearAllEvents(sessionId)
defaultNotificationDrawerManager.clearAllMessagesEvents(sessionId)
actionIds.dismissInvite -> if (roomId != null) {
defaultNotificationDrawerManager.clearMembershipNotificationForRoom(sessionId, roomId)
}

View file

@ -154,6 +154,11 @@ data class NotificationEventQueue constructor(
queue.removeAll { it is NotifiableMessageEvent && it.sessionId == sessionId }
}
fun clearAllForSession(sessionId: SessionId) {
Timber.d("clearAllForSession $sessionId")
queue.removeAll { it.sessionId == sessionId }
}
fun clearMessagesForRoom(sessionId: SessionId, roomId: RoomId) {
Timber.d("clearMessageEventOfRoom $sessionId, $roomId")
queue.removeAll { it is NotifiableMessageEvent && it.sessionId == sessionId && it.roomId == roomId }