Make NotificationDrawerManager.updateEvent private.
This commit is contained in:
parent
7e7aca4a53
commit
2afdf49501
3 changed files with 34 additions and 16 deletions
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue