Browse Source

Remove usage of `with(notificationDataFactory)` for code clarity.

pull/3320/head
Benoit Marty 1 month ago committed by Benoit Marty
parent
commit
19bca0775a
  1. 116
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt

116
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt

@ -42,77 +42,75 @@ class NotificationRenderer @Inject constructor(
imageLoader: ImageLoader, imageLoader: ImageLoader,
) { ) {
val groupedEvents = eventsToProcess.groupByType() val groupedEvents = eventsToProcess.groupByType()
with(notificationDataFactory) { val roomNotifications = notificationDataFactory.toNotifications(groupedEvents.roomEvents, currentUser, imageLoader)
val roomNotifications = toNotifications(groupedEvents.roomEvents, currentUser, imageLoader) val invitationNotifications = notificationDataFactory.toNotifications(groupedEvents.invitationEvents)
val invitationNotifications = toNotifications(groupedEvents.invitationEvents) val simpleNotifications = notificationDataFactory.toNotifications(groupedEvents.simpleEvents)
val simpleNotifications = toNotifications(groupedEvents.simpleEvents) val fallbackNotifications = notificationDataFactory.toNotifications(groupedEvents.fallbackEvents)
val fallbackNotifications = toNotifications(groupedEvents.fallbackEvents) val summaryNotification = notificationDataFactory.createSummaryNotification(
val summaryNotification = createSummaryNotification( currentUser = currentUser,
currentUser = currentUser, roomNotifications = roomNotifications,
roomNotifications = roomNotifications, invitationNotifications = invitationNotifications,
invitationNotifications = invitationNotifications, simpleNotifications = simpleNotifications,
simpleNotifications = simpleNotifications, fallbackNotifications = fallbackNotifications,
fallbackNotifications = fallbackNotifications, )
// Remove summary first to avoid briefly displaying it after dismissing the last notification
if (summaryNotification == SummaryNotification.Removed) {
Timber.tag(loggerTag.value).d("Removing summary notification")
notificationDisplayer.cancelNotificationMessage(
tag = null,
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId)
) )
}
// Remove summary first to avoid briefly displaying it after dismissing the last notification roomNotifications.forEach { notificationData ->
if (summaryNotification == SummaryNotification.Removed) { notificationDisplayer.showNotificationMessage(
Timber.tag(loggerTag.value).d("Removing summary notification") tag = notificationData.roomId.value,
notificationDisplayer.cancelNotificationMessage( id = NotificationIdProvider.getRoomMessagesNotificationId(currentUser.userId),
tag = null, notification = notificationData.notification
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId) )
) }
}
roomNotifications.forEach { notificationData -> invitationNotifications.forEach { notificationData ->
if (useCompleteNotificationFormat) {
Timber.tag(loggerTag.value).d("Updating invitation notification ${notificationData.key}")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotificationMessage(
tag = notificationData.roomId.value, tag = notificationData.key,
id = NotificationIdProvider.getRoomMessagesNotificationId(currentUser.userId), id = NotificationIdProvider.getRoomInvitationNotificationId(currentUser.userId),
notification = notificationData.notification notification = notificationData.notification
) )
} }
}
invitationNotifications.forEach { notificationData -> simpleNotifications.forEach { notificationData ->
if (useCompleteNotificationFormat) { if (useCompleteNotificationFormat) {
Timber.tag(loggerTag.value).d("Updating invitation notification ${notificationData.key}") Timber.tag(loggerTag.value).d("Updating simple notification ${notificationData.key}")
notificationDisplayer.showNotificationMessage(
tag = notificationData.key,
id = NotificationIdProvider.getRoomInvitationNotificationId(currentUser.userId),
notification = notificationData.notification
)
}
}
simpleNotifications.forEach { notificationData ->
if (useCompleteNotificationFormat) {
Timber.tag(loggerTag.value).d("Updating simple notification ${notificationData.key}")
notificationDisplayer.showNotificationMessage(
tag = notificationData.key,
id = NotificationIdProvider.getRoomEventNotificationId(currentUser.userId),
notification = notificationData.notification
)
}
}
// Show only the first fallback notification
if (fallbackNotifications.isNotEmpty()) {
Timber.tag(loggerTag.value).d("Showing fallback notification")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotificationMessage(
tag = "FALLBACK", tag = notificationData.key,
id = NotificationIdProvider.getFallbackNotificationId(currentUser.userId), id = NotificationIdProvider.getRoomEventNotificationId(currentUser.userId),
notification = fallbackNotifications.first().notification notification = notificationData.notification
) )
} }
}
// Update summary last to avoid briefly displaying it before other notifications // Show only the first fallback notification
if (summaryNotification is SummaryNotification.Update) { if (fallbackNotifications.isNotEmpty()) {
Timber.tag(loggerTag.value).d("Updating summary notification") Timber.tag(loggerTag.value).d("Showing fallback notification")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotificationMessage(
tag = null, tag = "FALLBACK",
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId), id = NotificationIdProvider.getFallbackNotificationId(currentUser.userId),
notification = summaryNotification.notification notification = fallbackNotifications.first().notification
) )
} }
// Update summary last to avoid briefly displaying it before other notifications
if (summaryNotification is SummaryNotification.Update) {
Timber.tag(loggerTag.value).d("Updating summary notification")
notificationDisplayer.showNotificationMessage(
tag = null,
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId),
notification = summaryNotification.notification
)
} }
} }
} }

Loading…
Cancel
Save