Browse Source

Make NotificationDrawerManager.updateEvent private.

test/jme/compound-poc
Benoit Marty 1 year ago committed by Benoit Marty
parent
commit
42889973af
  1. 8
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt
  2. 40
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDrawerManager.kt
  3. 2
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/PushHandler.kt

8
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt

@ -57,24 +57,24 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
handleSmartReply(intent, context) handleSmartReply(intent, context)
actionIds.dismissRoom -> actionIds.dismissRoom ->
intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId -> intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId ->
notificationDrawerManager.updateEvents { it.clearMessagesForRoom(sessionId, roomId) } notificationDrawerManager.clearMessagesForRoom(sessionId, roomId)
} }
actionIds.dismissSummary -> actionIds.dismissSummary ->
notificationDrawerManager.clearAllEvents(sessionId) notificationDrawerManager.clearAllEvents(sessionId)
actionIds.markRoomRead -> actionIds.markRoomRead ->
intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId -> intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId ->
notificationDrawerManager.updateEvents { it.clearMessagesForRoom(sessionId, roomId) } notificationDrawerManager.clearMessagesForRoom(sessionId, roomId)
handleMarkAsRead(sessionId, roomId) handleMarkAsRead(sessionId, roomId)
} }
actionIds.join -> { actionIds.join -> {
intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId -> intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId ->
notificationDrawerManager.updateEvents { it.clearMemberShipNotificationForRoom(sessionId, roomId) } notificationDrawerManager.clearMemberShipNotificationForRoom(sessionId, roomId)
handleJoinRoom(sessionId, roomId) handleJoinRoom(sessionId, roomId)
} }
} }
actionIds.reject -> { actionIds.reject -> {
intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId -> intent.getStringExtra(KEY_ROOM_ID)?.asRoomId()?.let { roomId ->
notificationDrawerManager.updateEvents { it.clearMemberShipNotificationForRoom(sessionId, roomId) } notificationDrawerManager.clearMemberShipNotificationForRoom(sessionId, roomId)
handleRejectRoom(sessionId, roomId) handleRejectRoom(sessionId, roomId)
} }
} }

40
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDrawerManager.kt

@ -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)
} }

2
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/PushHandler.kt

@ -134,7 +134,7 @@ class PushHandler @Inject constructor(
return return
} }
notificationDrawerManager.updateEvents { it.onNotifiableEventReceived(notificationData) } notificationDrawerManager.onNotifiableEventReceived(notificationData)
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag(loggerTag.value).e(e, "## handleInternal() failed") Timber.tag(loggerTag.value).e(e, "## handleInternal() failed")
} }

Loading…
Cancel
Save