|
|
@ -89,7 +89,7 @@ class NotificationDrawerManager @Inject constructor( |
|
|
|
is AppNavigationState.Space -> {} |
|
|
|
is AppNavigationState.Space -> {} |
|
|
|
is AppNavigationState.Room -> { |
|
|
|
is AppNavigationState.Room -> { |
|
|
|
// Cleanup notification for current room |
|
|
|
// Cleanup notification for current room |
|
|
|
onEnteringRoom(appNavigationState.parentSpace.parentSession.sessionId, appNavigationState.roomId) |
|
|
|
clearMessagesForRoom(appNavigationState.parentSpace.parentSession.sessionId, appNavigationState.roomId) |
|
|
|
} |
|
|
|
} |
|
|
|
is AppNavigationState.Thread -> { |
|
|
|
is AppNavigationState.Thread -> { |
|
|
|
onEnteringThread( |
|
|
|
onEnteringThread( |
|
|
@ -109,13 +109,7 @@ class NotificationDrawerManager @Inject constructor( |
|
|
|
return NotificationState(queuedEvents, renderedEvents) |
|
|
|
return NotificationState(queuedEvents, renderedEvents) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private fun NotificationEventQueue.onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { |
|
|
|
Should be called as soon as a new event is ready to be displayed. |
|
|
|
|
|
|
|
The notification corresponding to this event will not be displayed until |
|
|
|
|
|
|
|
#refreshNotificationDrawer() is called. |
|
|
|
|
|
|
|
Events might be grouped and there might not be one notification per event! |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun NotificationEventQueue.onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { |
|
|
|
|
|
|
|
if (!pushDataStore.areNotificationEnabledForDevice()) { |
|
|
|
if (!pushDataStore.areNotificationEnabledForDevice()) { |
|
|
|
Timber.i("Notification are disabled for this device") |
|
|
|
Timber.i("Notification are disabled for this device") |
|
|
|
return |
|
|
|
return |
|
|
@ -136,23 +130,47 @@ class NotificationDrawerManager @Inject constructor( |
|
|
|
add(notifiableEvent) |
|
|
|
add(notifiableEvent) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Should be called as soon as a new event is ready to be displayed. |
|
|
|
|
|
|
|
* The notification corresponding to this event will not be displayed until |
|
|
|
|
|
|
|
* #refreshNotificationDrawer() is called. |
|
|
|
|
|
|
|
* Events might be grouped and there might not be one notification per event! |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { |
|
|
|
|
|
|
|
updateEvents { |
|
|
|
|
|
|
|
it.onNotifiableEventReceived(notifiableEvent) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Clear all known events and refresh the notification drawer. |
|
|
|
* Clear all known events and refresh the notification drawer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun clearAllEvents(sessionId: SessionId) { |
|
|
|
fun clearAllEvents(sessionId: SessionId) { |
|
|
|
updateEvents { it.clearMessagesForSession(sessionId) } |
|
|
|
updateEvents { |
|
|
|
|
|
|
|
it.clearMessagesForSession(sessionId) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Should be called when the application is currently opened and showing timeline for the given roomId. |
|
|
|
* 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. |
|
|
|
* Used to ignore events related to that room (no need to display notification) and clean any existing notification on this room. |
|
|
|
|
|
|
|
* Can also be called when a notification for this room is dismissed by the user. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun onEnteringRoom(sessionId: SessionId, roomId: RoomId) { |
|
|
|
fun clearMessagesForRoom(sessionId: SessionId, roomId: RoomId) { |
|
|
|
updateEvents { |
|
|
|
updateEvents { |
|
|
|
it.clearMessagesForRoom(sessionId, roomId) |
|
|
|
it.clearMessagesForRoom(sessionId, roomId) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Clear invitation notification for the provided room. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun clearMemberShipNotificationForRoom(sessionId: SessionId, roomId: RoomId) { |
|
|
|
|
|
|
|
updateEvents { |
|
|
|
|
|
|
|
it.clearMemberShipNotificationForRoom(sessionId, roomId) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Should be called when the application is currently opened and showing timeline for the given threadId. |
|
|
|
* Should be called when the application is currently opened and showing timeline for the given threadId. |
|
|
|
* Used to ignore events related to that thread (no need to display notification) and clean any existing notification on this room. |
|
|
|
* Used to ignore events related to that thread (no need to display notification) and clean any existing notification on this room. |
|
|
@ -175,7 +193,7 @@ class NotificationDrawerManager @Inject constructor( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun updateEvents(action: NotificationDrawerManager.(NotificationEventQueue) -> Unit) { |
|
|
|
private fun updateEvents(action: NotificationDrawerManager.(NotificationEventQueue) -> Unit) { |
|
|
|
notificationState.updateQueuedEvents(this) { queuedEvents, _ -> |
|
|
|
notificationState.updateQueuedEvents(this) { queuedEvents, _ -> |
|
|
|
action(queuedEvents) |
|
|
|
action(queuedEvents) |
|
|
|
} |
|
|
|
} |
|
|
|