From be807f4b5c644d4f9e446c4ade81538faa7f105b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 4 Nov 2025 15:43:23 +0100 Subject: [PATCH] Revert "NotificationDataFactory: improve API" This reverts commit 7d7ea5d67c35bc7996b71fedb5b562fbc1710c9d. # Conflicts: # libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactoryTest.kt --- .../notifications/NotificationDataFactory.kt | 32 ++++++++++++------- .../notifications/NotificationRenderer.kt | 16 +++------- .../NotificationDataFactoryTest.kt | 15 ++++++--- .../fake/FakeNotificationDataFactory.kt | 20 +++++++----- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactory.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactory.kt index ab8406f1af..33b2df410c 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactory.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactory.kt @@ -28,26 +28,30 @@ import io.element.android.libraries.push.impl.notifications.model.SimpleNotifiab import io.element.android.services.toolbox.api.strings.StringProvider interface NotificationDataFactory { - suspend fun List.toNotifications( + suspend fun toNotifications( + messages: List, imageLoader: ImageLoader, notificationAccountParams: NotificationAccountParams, ): List @JvmName("toNotificationInvites") @Suppress("INAPPLICABLE_JVM_NAME") - fun List.toNotifications( + fun toNotifications( + invites: List, notificationAccountParams: NotificationAccountParams, ): List @JvmName("toNotificationSimpleEvents") @Suppress("INAPPLICABLE_JVM_NAME") - fun List.toNotifications( + fun toNotifications( + simpleEvents: List, notificationAccountParams: NotificationAccountParams, ): List @JvmName("toNotificationFallbackEvents") @Suppress("INAPPLICABLE_JVM_NAME") - fun List.toNotifications( + fun toNotifications( + fallback: List, notificationAccountParams: NotificationAccountParams, ): List @@ -68,11 +72,12 @@ class DefaultNotificationDataFactory( private val activeNotificationsProvider: ActiveNotificationsProvider, private val stringProvider: StringProvider, ) : NotificationDataFactory { - override suspend fun List.toNotifications( + override suspend fun toNotifications( + messages: List, imageLoader: ImageLoader, notificationAccountParams: NotificationAccountParams, ): List { - val messagesToDisplay = filterNot { it.canNotBeDisplayed() } + val messagesToDisplay = messages.filterNot { it.canNotBeDisplayed() } .groupBy { it.roomId } return messagesToDisplay.flatMap { (roomId, events) -> val roomName = events.lastOrNull()?.roomName ?: roomId.value @@ -109,10 +114,11 @@ class DefaultNotificationDataFactory( @JvmName("toNotificationInvites") @Suppress("INAPPLICABLE_JVM_NAME") - override fun List.toNotifications( + override fun toNotifications( + invites: List, notificationAccountParams: NotificationAccountParams, ): List { - return map { event -> + return invites.map { event -> OneShotNotification( tag = event.roomId.value, notification = notificationCreator.createRoomInvitationNotification(notificationAccountParams, event), @@ -125,10 +131,11 @@ class DefaultNotificationDataFactory( @JvmName("toNotificationSimpleEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun List.toNotifications( + override fun toNotifications( + simpleEvents: List, notificationAccountParams: NotificationAccountParams, ): List { - return map { event -> + return simpleEvents.map { event -> OneShotNotification( tag = event.eventId.value, notification = notificationCreator.createSimpleEventNotification(notificationAccountParams, event), @@ -141,10 +148,11 @@ class DefaultNotificationDataFactory( @JvmName("toNotificationFallbackEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun List.toNotifications( + override fun toNotifications( + fallback: List, notificationAccountParams: NotificationAccountParams, ): List { - return map { event -> + return fallback.map { event -> OneShotNotification( tag = event.eventId.value, notification = notificationCreator.createFallbackNotification(notificationAccountParams, event), diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt index 9f24ccecb0..0cfe083caf 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRenderer.kt @@ -51,18 +51,10 @@ class NotificationRenderer( showSessionId = numberOfAccounts > 1, ) val groupedEvents = eventsToProcess.groupByType() - val roomNotifications = with(notificationDataFactory) { - groupedEvents.roomEvents.toNotifications(imageLoader, notificationAccountParams) - } - val invitationNotifications = with(notificationDataFactory) { - groupedEvents.invitationEvents.toNotifications(notificationAccountParams) - } - val simpleNotifications = with(notificationDataFactory) { - groupedEvents.simpleEvents.toNotifications(notificationAccountParams) - } - val fallbackNotifications = with(notificationDataFactory) { - groupedEvents.fallbackEvents.toNotifications(notificationAccountParams) - } + val roomNotifications = notificationDataFactory.toNotifications(groupedEvents.roomEvents, imageLoader, notificationAccountParams) + val invitationNotifications = notificationDataFactory.toNotifications(groupedEvents.invitationEvents, notificationAccountParams) + val simpleNotifications = notificationDataFactory.toNotifications(groupedEvents.simpleEvents, notificationAccountParams) + val fallbackNotifications = notificationDataFactory.toNotifications(groupedEvents.fallbackEvents, notificationAccountParams) val summaryNotification = notificationDataFactory.createSummaryNotification( roomNotifications = roomNotifications, invitationNotifications = invitationNotifications, diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactoryTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactoryTest.kt index 50e0b5dfb8..6971fcbc41 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactoryTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactoryTest.kt @@ -55,7 +55,9 @@ class NotificationDataFactoryTest { aNotificationAccountParams(), AN_INVITATION_EVENT, ) - val result = listOf(AN_INVITATION_EVENT).toNotifications(aNotificationAccountParams()) + val roomInvitation = listOf(AN_INVITATION_EVENT) + val result = toNotifications(roomInvitation, aNotificationAccountParams()) + assertThat(result).isEqualTo( listOf( OneShotNotification( @@ -75,7 +77,7 @@ class NotificationDataFactoryTest { aNotificationAccountParams(), AN_INVITATION_EVENT, ) - val result = listOf(A_SIMPLE_EVENT).toNotifications(aNotificationAccountParams()) + val result = toNotifications(listOf(A_SIMPLE_EVENT), aNotificationAccountParams()) assertThat(result).containsExactly( OneShotNotification( notification = expectedNotification, @@ -109,7 +111,8 @@ class NotificationDataFactoryTest { threadId = null, ) val fakeImageLoader = FakeImageLoader() - val result = listOf(A_MESSAGE_EVENT).toNotifications( + val result = toNotifications( + messages = listOf(A_MESSAGE_EVENT), notificationAccountParams = aNotificationAccountParams( user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), ), @@ -125,7 +128,8 @@ class NotificationDataFactoryTest { fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationDataFactory) { val redactedRoom = A_MESSAGE_EVENT.copy(isRedacted = true) val fakeImageLoader = FakeImageLoader() - val result = listOf(redactedRoom).toNotifications( + val result = toNotifications( + messages = listOf(redactedRoom), notificationAccountParams = aNotificationAccountParams( user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), ), @@ -164,7 +168,8 @@ class NotificationDataFactoryTest { ) val fakeImageLoader = FakeImageLoader() - val result = roomWithRedactedMessage.toNotifications( + val result = toNotifications( + messages = roomWithRedactedMessage, notificationAccountParams = aNotificationAccountParams( user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), ), diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationDataFactory.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationDataFactory.kt index 89326f5ad9..a897dbfc09 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationDataFactory.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationDataFactory.kt @@ -40,35 +40,39 @@ class FakeNotificationDataFactory( var fallbackEventToNotificationsResult: LambdaOneParamRecorder, List> = lambdaRecorder { _ -> emptyList() }, ) : NotificationDataFactory { - override suspend fun List.toNotifications( + override suspend fun toNotifications( + messages: List, imageLoader: ImageLoader, notificationAccountParams: NotificationAccountParams, ): List { - return messageEventToNotificationsResult(this, imageLoader, notificationAccountParams) + return messageEventToNotificationsResult(messages, imageLoader, notificationAccountParams) } @JvmName("toNotificationInvites") @Suppress("INAPPLICABLE_JVM_NAME") - override fun List.toNotifications( + override fun toNotifications( + invites: List, notificationAccountParams: NotificationAccountParams, ): List { - return inviteToNotificationsResult(this) + return inviteToNotificationsResult(invites) } @JvmName("toNotificationSimpleEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun List.toNotifications( + override fun toNotifications( + simpleEvents: List, notificationAccountParams: NotificationAccountParams, ): List { - return simpleEventToNotificationsResult(this) + return simpleEventToNotificationsResult(simpleEvents) } @JvmName("toNotificationFallbackEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun List.toNotifications( + override fun toNotifications( + fallback: List, notificationAccountParams: NotificationAccountParams, ): List { - return fallbackEventToNotificationsResult(this) + return fallbackEventToNotificationsResult(fallback) } override fun createSummaryNotification(