diff --git a/enterprise b/enterprise index 867d1118e1..a3e54addf0 160000 --- a/enterprise +++ b/enterprise @@ -1 +1 @@ -Subproject commit 867d1118e157ba89a4f5462f8d9c13e206f10026 +Subproject commit a3e54addf0d61189bb6868f9b5dc733a6a1fb3ea diff --git a/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt index 0c855c3a82..785afd115a 100644 --- a/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt +++ b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt @@ -7,6 +7,7 @@ package io.element.android.features.enterprise.api +import androidx.compose.ui.graphics.Color import io.element.android.compound.colors.SemanticColorsLightDark import io.element.android.libraries.matrix.api.core.SessionId import kotlinx.coroutines.flow.Flow @@ -24,6 +25,8 @@ interface EnterpriseService { */ suspend fun overrideBrandColor(sessionId: SessionId?, brandColor: String?) + fun brandColorsFlow(sessionId: SessionId?): Flow + fun semanticColorsFlow(sessionId: SessionId?): Flow fun firebasePushGateway(): String? diff --git a/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt b/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt index 7207654bd2..b53e30c080 100644 --- a/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt +++ b/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt @@ -7,6 +7,7 @@ package io.element.android.features.enterprise.impl +import androidx.compose.ui.graphics.Color import dev.zacsweers.metro.AppScope import dev.zacsweers.metro.ContributesBinding import io.element.android.compound.colors.SemanticColorsLightDark @@ -27,6 +28,10 @@ class DefaultEnterpriseService : EnterpriseService { override suspend fun overrideBrandColor(sessionId: SessionId?, brandColor: String?) = Unit + override fun brandColorsFlow(sessionId: SessionId?): Flow { + return flowOf(null) + } + override fun semanticColorsFlow(sessionId: SessionId?): Flow { return flowOf(SemanticColorsLightDark.default) } diff --git a/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt b/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt index 2aedd1edbd..39b7c320d9 100644 --- a/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt +++ b/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt @@ -7,6 +7,7 @@ package io.element.android.features.enterprise.test +import androidx.compose.ui.graphics.Color import io.element.android.compound.colors.SemanticColorsLightDark import io.element.android.features.enterprise.api.BugReportUrl import io.element.android.features.enterprise.api.EnterpriseService @@ -27,6 +28,7 @@ class FakeEnterpriseService( private val firebasePushGatewayResult: () -> String? = { lambdaError() }, private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() }, ) : EnterpriseService { + private val brandColorState = MutableStateFlow(null) private val semanticColorsState = MutableStateFlow(initialSemanticColors) override suspend fun isEnterpriseUser(sessionId: SessionId): Boolean = simulateLongTask { @@ -45,6 +47,10 @@ class FakeEnterpriseService( overrideBrandColorResult(sessionId, brandColor) } + override fun brandColorsFlow(sessionId: SessionId?): Flow { + return brandColorState.asStateFlow() + } + override fun semanticColorsFlow(sessionId: SessionId?): Flow { return semanticColorsState.asStateFlow() } diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/TestData.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/TestData.kt index f05f6958c0..8db5fc6807 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/TestData.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/TestData.kt @@ -98,3 +98,5 @@ const val A_TIMESTAMP = 567L const val A_FORMATTED_DATE = "April 6, 1980 at 6:35 PM" const val A_LOGIN_HINT = "mxid:@alice:example.org" + +const val A_COLOR_INT = 0xFF0000 diff --git a/libraries/push/impl/build.gradle.kts b/libraries/push/impl/build.gradle.kts index 3d053a4657..87b3c681f1 100644 --- a/libraries/push/impl/build.gradle.kts +++ b/libraries/push/impl/build.gradle.kts @@ -56,6 +56,7 @@ dependencies { implementation(projects.libraries.troubleshoot.api) implementation(projects.libraries.workmanager.api) implementation(projects.features.call.api) + implementation(projects.features.enterprise.api) implementation(projects.features.lockscreen.api) implementation(projects.libraries.featureflag.api) api(projects.libraries.pushproviders.api) @@ -77,6 +78,7 @@ dependencies { testImplementation(projects.libraries.troubleshoot.test) testImplementation(projects.libraries.workmanager.test) testImplementation(projects.features.call.test) + testImplementation(projects.features.enterprise.test) testImplementation(projects.features.lockscreen.test) testImplementation(projects.features.networkmonitor.test) testImplementation(projects.services.appnavstate.test) 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 09fc7058dc..38ab52e084 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 @@ -10,6 +10,7 @@ package io.element.android.libraries.push.impl.notifications import android.app.Notification import android.graphics.Typeface import android.text.style.StyleSpan +import androidx.annotation.ColorInt import androidx.core.text.buildSpannedString import androidx.core.text.inSpans import coil3.ImageLoader @@ -31,17 +32,29 @@ interface NotificationDataFactory { messages: List, currentUser: MatrixUser, imageLoader: ImageLoader, + @ColorInt color: Int, ): List @JvmName("toNotificationInvites") @Suppress("INAPPLICABLE_JVM_NAME") - fun toNotifications(invites: List): List + fun toNotifications( + invites: List, + @ColorInt color: Int, + ): List + @JvmName("toNotificationSimpleEvents") @Suppress("INAPPLICABLE_JVM_NAME") - fun toNotifications(simpleEvents: List): List + fun toNotifications( + simpleEvents: List, + @ColorInt color: Int, + ): List + @JvmName("toNotificationFallbackEvents") @Suppress("INAPPLICABLE_JVM_NAME") - fun toNotifications(fallback: List): List + fun toNotifications( + fallback: List, + @ColorInt color: Int, + ): List fun createSummaryNotification( currentUser: MatrixUser, @@ -49,6 +62,7 @@ interface NotificationDataFactory { invitationNotifications: List, simpleNotifications: List, fallbackNotifications: List, + @ColorInt color: Int, ): SummaryNotification } @@ -64,6 +78,7 @@ class DefaultNotificationDataFactory( messages: List, currentUser: MatrixUser, imageLoader: ImageLoader, + @ColorInt color: Int, ): List { val messagesToDisplay = messages.filterNot { it.canNotBeDisplayed() } .groupBy { it.roomId } @@ -76,6 +91,7 @@ class DefaultNotificationDataFactory( roomId = roomId, imageLoader = imageLoader, existingNotification = getExistingNotificationForMessages(currentUser.userId, roomId), + color = color, ) RoomNotification( notification = notification, @@ -96,11 +112,14 @@ class DefaultNotificationDataFactory( @JvmName("toNotificationInvites") @Suppress("INAPPLICABLE_JVM_NAME") - override fun toNotifications(invites: List): List { + override fun toNotifications( + invites: List, + @ColorInt color: Int, + ): List { return invites.map { event -> OneShotNotification( key = event.roomId.value, - notification = notificationCreator.createRoomInvitationNotification(event), + notification = notificationCreator.createRoomInvitationNotification(event, color), summaryLine = event.description, isNoisy = event.noisy, timestamp = event.timestamp @@ -110,11 +129,14 @@ class DefaultNotificationDataFactory( @JvmName("toNotificationSimpleEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun toNotifications(simpleEvents: List): List { + override fun toNotifications( + simpleEvents: List, + @ColorInt color: Int, + ): List { return simpleEvents.map { event -> OneShotNotification( key = event.eventId.value, - notification = notificationCreator.createSimpleEventNotification(event), + notification = notificationCreator.createSimpleEventNotification(event, color), summaryLine = event.description, isNoisy = event.noisy, timestamp = event.timestamp @@ -124,11 +146,14 @@ class DefaultNotificationDataFactory( @JvmName("toNotificationFallbackEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun toNotifications(fallback: List): List { + override fun toNotifications( + fallback: List, + @ColorInt color: Int, + ): List { return fallback.map { event -> OneShotNotification( key = event.eventId.value, - notification = notificationCreator.createFallbackNotification(event), + notification = notificationCreator.createFallbackNotification(event, color), summaryLine = event.description.orEmpty(), isNoisy = false, timestamp = event.timestamp @@ -142,6 +167,7 @@ class DefaultNotificationDataFactory( invitationNotifications: List, simpleNotifications: List, fallbackNotifications: List, + @ColorInt color: Int, ): SummaryNotification { return when { roomNotifications.isEmpty() && invitationNotifications.isEmpty() && simpleNotifications.isEmpty() -> SummaryNotification.Removed @@ -152,6 +178,7 @@ class DefaultNotificationDataFactory( invitationNotifications = invitationNotifications, simpleNotifications = simpleNotifications, fallbackNotifications = fallbackNotifications, + color = color, ) ) } 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 5d901abbc9..c70148ca25 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 @@ -7,8 +7,11 @@ package io.element.android.libraries.push.impl.notifications +import androidx.compose.ui.graphics.toArgb import coil3.ImageLoader import dev.zacsweers.metro.Inject +import io.element.android.appconfig.NotificationConfig +import io.element.android.features.enterprise.api.EnterpriseService import io.element.android.libraries.core.log.logger.LoggerTag import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.push.api.notifications.NotificationIdProvider @@ -18,6 +21,7 @@ import io.element.android.libraries.push.impl.notifications.model.NotifiableEven import io.element.android.libraries.push.impl.notifications.model.NotifiableMessageEvent import io.element.android.libraries.push.impl.notifications.model.NotifiableRingingCallEvent import io.element.android.libraries.push.impl.notifications.model.SimpleNotifiableEvent +import kotlinx.coroutines.flow.first import timber.log.Timber private val loggerTag = LoggerTag("NotificationRenderer", LoggerTag.NotificationLoggerTag) @@ -26,6 +30,7 @@ private val loggerTag = LoggerTag("NotificationRenderer", LoggerTag.Notification class NotificationRenderer( private val notificationDisplayer: NotificationDisplayer, private val notificationDataFactory: NotificationDataFactory, + private val enterpriseService: EnterpriseService, ) { suspend fun render( currentUser: MatrixUser, @@ -33,17 +38,20 @@ class NotificationRenderer( eventsToProcess: List, imageLoader: ImageLoader, ) { + val color = enterpriseService.brandColorsFlow(currentUser.userId).first()?.toArgb() + ?: NotificationConfig.NOTIFICATION_ACCENT_COLOR val groupedEvents = eventsToProcess.groupByType() - val roomNotifications = notificationDataFactory.toNotifications(groupedEvents.roomEvents, currentUser, imageLoader) - val invitationNotifications = notificationDataFactory.toNotifications(groupedEvents.invitationEvents) - val simpleNotifications = notificationDataFactory.toNotifications(groupedEvents.simpleEvents) - val fallbackNotifications = notificationDataFactory.toNotifications(groupedEvents.fallbackEvents) + val roomNotifications = notificationDataFactory.toNotifications(groupedEvents.roomEvents, currentUser, imageLoader, color) + val invitationNotifications = notificationDataFactory.toNotifications(groupedEvents.invitationEvents, color) + val simpleNotifications = notificationDataFactory.toNotifications(groupedEvents.simpleEvents, color) + val fallbackNotifications = notificationDataFactory.toNotifications(groupedEvents.fallbackEvents, color) val summaryNotification = notificationDataFactory.createSummaryNotification( currentUser = currentUser, roomNotifications = roomNotifications, invitationNotifications = invitationNotifications, simpleNotifications = simpleNotifications, fallbackNotifications = fallbackNotifications, + color = color, ) // Remove summary first to avoid briefly displaying it after dismissing the last notification diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/RoomGroupMessageCreator.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/RoomGroupMessageCreator.kt index cd75424225..bf6ac73522 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/RoomGroupMessageCreator.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/RoomGroupMessageCreator.kt @@ -9,6 +9,7 @@ package io.element.android.libraries.push.impl.notifications import android.app.Notification import android.graphics.Bitmap +import androidx.annotation.ColorInt import coil3.ImageLoader import dev.zacsweers.metro.AppScope import dev.zacsweers.metro.ContributesBinding @@ -28,6 +29,7 @@ interface RoomGroupMessageCreator { roomId: RoomId, imageLoader: ImageLoader, existingNotification: Notification?, + @ColorInt color: Int, ): Notification } @@ -43,6 +45,7 @@ class DefaultRoomGroupMessageCreator( roomId: RoomId, imageLoader: ImageLoader, existingNotification: Notification?, + @ColorInt color: Int, ): Notification { val lastKnownRoomEvent = events.last() val roomName = lastKnownRoomEvent.roomName ?: lastKnownRoomEvent.senderDisambiguatedDisplayName ?: "Room name (${roomId.value.take(8)}…)" @@ -60,24 +63,25 @@ class DefaultRoomGroupMessageCreator( val smartReplyErrors = events.filter { it.isSmartReplyError() } val roomIsDm = !roomIsGroup return notificationCreator.createMessagesListNotification( - RoomEventGroupInfo( - sessionId = currentUser.userId, - roomId = roomId, - roomDisplayName = roomName, - isDm = roomIsDm, - hasSmartReplyError = smartReplyErrors.isNotEmpty(), - shouldBing = events.any { it.noisy }, - customSound = events.last().soundName, - isUpdated = events.last().isUpdated, - ), - threadId = lastKnownRoomEvent.threadId, - largeIcon = largeBitmap, - lastMessageTimestamp = lastMessageTimestamp, - tickerText = tickerText, - currentUser = currentUser, - existingNotification = existingNotification, - imageLoader = imageLoader, - events = events, + RoomEventGroupInfo( + sessionId = currentUser.userId, + roomId = roomId, + roomDisplayName = roomName, + isDm = roomIsDm, + hasSmartReplyError = smartReplyErrors.isNotEmpty(), + shouldBing = events.any { it.noisy }, + customSound = events.last().soundName, + isUpdated = events.last().isUpdated, + ), + threadId = lastKnownRoomEvent.threadId, + largeIcon = largeBitmap, + lastMessageTimestamp = lastMessageTimestamp, + tickerText = tickerText, + currentUser = currentUser, + existingNotification = existingNotification, + imageLoader = imageLoader, + events = events, + color = color, ) } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt index f217b303aa..85947226f1 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt @@ -8,6 +8,7 @@ package io.element.android.libraries.push.impl.notifications import android.app.Notification +import androidx.annotation.ColorInt import dev.zacsweers.metro.AppScope import dev.zacsweers.metro.ContributesBinding import io.element.android.libraries.matrix.api.user.MatrixUser @@ -22,6 +23,7 @@ interface SummaryGroupMessageCreator { invitationNotifications: List, simpleNotifications: List, fallbackNotifications: List, + @ColorInt color: Int, ): Notification } @@ -45,6 +47,7 @@ class DefaultSummaryGroupMessageCreator( invitationNotifications: List, simpleNotifications: List, fallbackNotifications: List, + @ColorInt color: Int, ): Notification { val summaryIsNoisy = roomNotifications.any { it.shouldBing } || invitationNotifications.any { it.isNoisy } || @@ -61,7 +64,8 @@ class DefaultSummaryGroupMessageCreator( currentUser, sumTitle, noisy = summaryIsNoisy, - lastMessageTimestamp = lastMessageTimestamp + lastMessageTimestamp = lastMessageTimestamp, + color = color, ) } } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt index ab2dae4fb3..8e5605ccaf 100755 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt @@ -11,6 +11,7 @@ import android.app.Notification import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.MessagingStyle @@ -19,7 +20,6 @@ import androidx.core.content.res.ResourcesCompat import coil3.ImageLoader import dev.zacsweers.metro.AppScope import dev.zacsweers.metro.ContributesBinding -import io.element.android.appconfig.NotificationConfig import io.element.android.libraries.core.meta.BuildMeta import io.element.android.libraries.designsystem.utils.CommonDrawables import io.element.android.libraries.di.annotations.ApplicationContext @@ -57,18 +57,22 @@ interface NotificationCreator { existingNotification: Notification?, imageLoader: ImageLoader, events: List, + @ColorInt color: Int, ): Notification fun createRoomInvitationNotification( - inviteNotifiableEvent: InviteNotifiableEvent + inviteNotifiableEvent: InviteNotifiableEvent, + @ColorInt color: Int, ): Notification fun createSimpleEventNotification( simpleNotifiableEvent: SimpleNotifiableEvent, + @ColorInt color: Int, ): Notification fun createFallbackNotification( fallbackNotifiableEvent: FallbackNotifiableEvent, + @ColorInt color: Int, ): Notification /** @@ -78,10 +82,13 @@ interface NotificationCreator { currentUser: MatrixUser, compatSummary: String, noisy: Boolean, - lastMessageTimestamp: Long + lastMessageTimestamp: Long, + @ColorInt color: Int, ): Notification - fun createDiagnosticNotification(): Notification + fun createDiagnosticNotification( + @ColorInt color: Int, + ): Notification } @ContributesBinding(AppScope::class) @@ -97,8 +104,6 @@ class DefaultNotificationCreator( private val acceptInvitationActionFactory: AcceptInvitationActionFactory, private val rejectInvitationActionFactory: RejectInvitationActionFactory ) : NotificationCreator { - private val accentColor = NotificationConfig.NOTIFICATION_ACCENT_COLOR - /** * Create a notification for a Room. */ @@ -112,15 +117,14 @@ class DefaultNotificationCreator( existingNotification: Notification?, imageLoader: ImageLoader, events: List, + @ColorInt color: Int, ): Notification { // Build the pending intent for when the notification is clicked val openIntent = when { threadId != null -> pendingIntentFactory.createOpenThreadPendingIntent(roomInfo, threadId) else -> pendingIntentFactory.createOpenRoomPendingIntent(roomInfo.sessionId, roomInfo.roomId) } - val smallIcon = CommonDrawables.ic_notification - val containsMissedCall = events.any { it.type == EventType.RTC_NOTIFICATION } val channelId = if (containsMissedCall) { notificationChannels.getChannelForIncomingCall(false) @@ -176,7 +180,7 @@ class DefaultNotificationCreator( ) .setSmallIcon(smallIcon) // Set primary color (important for Wear 2.0 Notifications). - .setColor(accentColor) + .setColor(color) // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for // 'importance' which is set in the NotificationChannel. The integers representing // 'priority' are different from 'importance', so make sure you don't mix them. @@ -189,7 +193,7 @@ class DefaultNotificationCreator( setSound(it) } */ - setLights(accentColor, 500, 500) + setLights(color, 500, 500) } else { priority = NotificationCompat.PRIORITY_LOW } @@ -221,7 +225,8 @@ class DefaultNotificationCreator( } override fun createRoomInvitationNotification( - inviteNotifiableEvent: InviteNotifiableEvent + inviteNotifiableEvent: InviteNotifiableEvent, + @ColorInt color: Int, ): Notification { val smallIcon = CommonDrawables.ic_notification val channelId = notificationChannels.getChannelIdForMessage(inviteNotifiableEvent.noisy) @@ -232,7 +237,7 @@ class DefaultNotificationCreator( .setGroup(inviteNotifiableEvent.sessionId.value) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_ALL) .setSmallIcon(smallIcon) - .setColor(accentColor) + .setColor(color) .apply { addAction(rejectInvitationActionFactory.create(inviteNotifiableEvent)) addAction(acceptInvitationActionFactory.create(inviteNotifiableEvent)) @@ -247,7 +252,7 @@ class DefaultNotificationCreator( setSound(it) } */ - setLights(accentColor, 500, 500) + setLights(color, 500, 500) } else { priority = NotificationCompat.PRIORITY_LOW } @@ -264,9 +269,9 @@ class DefaultNotificationCreator( override fun createSimpleEventNotification( simpleNotifiableEvent: SimpleNotifiableEvent, + @ColorInt color: Int, ): Notification { val smallIcon = CommonDrawables.ic_notification - val channelId = notificationChannels.getChannelIdForMessage(simpleNotifiableEvent.noisy) return NotificationCompat.Builder(context, channelId) .setOnlyAlertOnce(true) @@ -275,7 +280,7 @@ class DefaultNotificationCreator( .setGroup(simpleNotifiableEvent.sessionId.value) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_ALL) .setSmallIcon(smallIcon) - .setColor(accentColor) + .setColor(color) .setAutoCancel(true) .setContentIntent(pendingIntentFactory.createOpenRoomPendingIntent(simpleNotifiableEvent.sessionId, simpleNotifiableEvent.roomId)) .apply { @@ -287,7 +292,7 @@ class DefaultNotificationCreator( setSound(it) } */ - setLights(accentColor, 500, 500) + setLights(color, 500, 500) } else { priority = NotificationCompat.PRIORITY_LOW } @@ -297,9 +302,9 @@ class DefaultNotificationCreator( override fun createFallbackNotification( fallbackNotifiableEvent: FallbackNotifiableEvent, + @ColorInt color: Int, ): Notification { val smallIcon = CommonDrawables.ic_notification - val channelId = notificationChannels.getChannelIdForMessage(false) return NotificationCompat.Builder(context, channelId) .setOnlyAlertOnce(true) @@ -308,7 +313,7 @@ class DefaultNotificationCreator( .setGroup(fallbackNotifiableEvent.sessionId.value) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_ALL) .setSmallIcon(smallIcon) - .setColor(accentColor) + .setColor(color) .setAutoCancel(true) .setWhen(fallbackNotifiableEvent.timestamp) // Ideally we'd use `createOpenRoomPendingIntent` here, but the broken notification might apply to an invite @@ -332,7 +337,8 @@ class DefaultNotificationCreator( currentUser: MatrixUser, compatSummary: String, noisy: Boolean, - lastMessageTimestamp: Long + lastMessageTimestamp: Long, + @ColorInt color: Int, ): Notification { val smallIcon = CommonDrawables.ic_notification val channelId = notificationChannels.getChannelIdForMessage(noisy) @@ -345,7 +351,7 @@ class DefaultNotificationCreator( .setGroup(currentUser.userId.value) // set this notification as the summary for the group .setGroupSummary(true) - .setColor(accentColor) + .setColor(color) .apply { if (noisy) { // Compat @@ -355,7 +361,7 @@ class DefaultNotificationCreator( setSound(it) } */ - setLights(accentColor, 500, 500) + setLights(color, 500, 500) } else { // compat priority = NotificationCompat.PRIORITY_LOW @@ -366,14 +372,16 @@ class DefaultNotificationCreator( .build() } - override fun createDiagnosticNotification(): Notification { + override fun createDiagnosticNotification( + @ColorInt color: Int, + ): Notification { val intent = pendingIntentFactory.createTestPendingIntent() return NotificationCompat.Builder(context, notificationChannels.getChannelIdForTest()) .setContentTitle(buildMeta.applicationName) .setContentText(stringProvider.getString(R.string.notification_test_push_notification_content)) .setSmallIcon(CommonDrawables.ic_notification) .setLargeIcon(getBitmap(R.drawable.element_logo_green)) - .setColor(accentColor) + .setColor(color) .setPriority(NotificationCompat.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_STATUS) .setAutoCancel(true) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt index da390f85f2..b217247aa2 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt @@ -7,9 +7,13 @@ package io.element.android.libraries.push.impl.troubleshoot -import dev.zacsweers.metro.AppScope +import androidx.compose.ui.graphics.toArgb import dev.zacsweers.metro.ContributesIntoSet import dev.zacsweers.metro.Inject +import io.element.android.appconfig.NotificationConfig +import io.element.android.features.enterprise.api.EnterpriseService +import io.element.android.libraries.di.SessionScope +import io.element.android.libraries.matrix.api.core.SessionId import io.element.android.libraries.push.impl.R import io.element.android.libraries.push.impl.notifications.NotificationDisplayer import io.element.android.libraries.push.impl.notifications.factories.NotificationCreator @@ -25,13 +29,15 @@ import kotlinx.coroutines.withTimeout import timber.log.Timber import kotlin.time.Duration.Companion.seconds -@ContributesIntoSet(AppScope::class) +@ContributesIntoSet(SessionScope::class) @Inject class NotificationTest( + private val sessionId: SessionId, private val notificationCreator: NotificationCreator, private val notificationDisplayer: NotificationDisplayer, private val notificationClickHandler: NotificationClickHandler, private val stringProvider: StringProvider, + private val enterpriseService: EnterpriseService, ) : NotificationTroubleshootTest { override val order = 50 private val delegate = NotificationTroubleshootTestDelegate( @@ -43,7 +49,9 @@ class NotificationTest( override suspend fun run(coroutineScope: CoroutineScope) { delegate.start() - val notification = notificationCreator.createDiagnosticNotification() + val color = enterpriseService.brandColorsFlow(sessionId).first()?.toArgb() + ?: NotificationConfig.NOTIFICATION_ACCENT_COLOR + val notification = notificationCreator.createDiagnosticNotification(color) val result = notificationDisplayer.displayDiagnosticNotification(notification) if (result) { coroutineScope.listenToNotificationClick() diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultBaseRoomGroupMessageCreatorTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultBaseRoomGroupMessageCreatorTest.kt index ba4e1657a7..ad872cfd1d 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultBaseRoomGroupMessageCreatorTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultBaseRoomGroupMessageCreatorTest.kt @@ -13,6 +13,7 @@ import androidx.core.app.NotificationCompat import com.google.common.truth.Truth.assertThat import io.element.android.appconfig.NotificationConfig import io.element.android.libraries.matrix.api.media.MediaSource +import io.element.android.libraries.matrix.test.A_COLOR_INT import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_TIMESTAMP import io.element.android.libraries.matrix.ui.components.aMatrixUser @@ -52,6 +53,7 @@ class DefaultBaseRoomGroupMessageCreatorTest { roomId = A_ROOM_ID, imageLoader = fakeImageLoader.getImageLoader(), existingNotification = null, + color = A_COLOR_INT, ) assertThat(result.number).isEqualTo(1) @Suppress("DEPRECATION") @@ -74,6 +76,7 @@ class DefaultBaseRoomGroupMessageCreatorTest { roomId = A_ROOM_ID, imageLoader = fakeImageLoader.getImageLoader(), existingNotification = null, + color = A_COLOR_INT, ) @Suppress("DEPRECATION") assertThat(result.priority).isEqualTo(NotificationCompat.PRIORITY_DEFAULT) @@ -138,6 +141,7 @@ class DefaultBaseRoomGroupMessageCreatorTest { roomId = A_ROOM_ID, imageLoader = fakeImageLoader.getImageLoader(), existingNotification = null, + color = A_COLOR_INT, ) assertThat(result.number).isEqualTo(1) assertThat(fakeImageLoader.getCoilRequests()).containsExactlyElementsIn(expectedCoilRequests) @@ -156,6 +160,7 @@ class DefaultBaseRoomGroupMessageCreatorTest { roomId = A_ROOM_ID, imageLoader = fakeImageLoader.getImageLoader(), existingNotification = null, + color = A_COLOR_INT, ) assertThat(result.number).isEqualTo(2) assertThat(result.`when`).isEqualTo(A_TIMESTAMP + 10) @@ -184,6 +189,7 @@ class DefaultBaseRoomGroupMessageCreatorTest { roomId = A_ROOM_ID, imageLoader = fakeImageLoader.getImageLoader(), existingNotification = null, + color = A_COLOR_INT, ) val actionTitles = result.actions?.map { it.title } assertThat(actionTitles).isEqualTo( @@ -208,6 +214,7 @@ class DefaultBaseRoomGroupMessageCreatorTest { roomId = A_ROOM_ID, imageLoader = fakeImageLoader.getImageLoader(), existingNotification = null, + color = A_COLOR_INT, ) assertThat(result.number).isEqualTo(1) assertThat(result.`when`).isEqualTo(A_TIMESTAMP) diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManagerTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManagerTest.kt index 07702602e8..36c406d129 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManagerTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManagerTest.kt @@ -10,6 +10,7 @@ package io.element.android.libraries.push.impl.notifications import android.app.Notification import androidx.core.app.NotificationManagerCompat import com.google.common.truth.Truth.assertThat +import io.element.android.features.enterprise.test.FakeEnterpriseService import io.element.android.libraries.matrix.test.AN_AVATAR_URL import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.A_ROOM_ID @@ -199,6 +200,7 @@ class DefaultNotificationDrawerManagerTest { activeNotificationsProvider = activeNotificationsProvider, stringProvider = FakeStringProvider(), ), + enterpriseService = FakeEnterpriseService(), ), appNavigationStateService = appNavigationStateService, coroutineScope = this, diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt index 25e00f7977..8b668a7f77 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt @@ -7,6 +7,7 @@ package io.element.android.libraries.push.impl.notifications +import io.element.android.features.enterprise.test.FakeEnterpriseService import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_SESSION_ID @@ -55,6 +56,7 @@ class DefaultOnMissedCallNotificationHandlerTest { notificationRenderer = NotificationRenderer( notificationDisplayer = FakeNotificationDisplayer(), notificationDataFactory = dataFactory, + enterpriseService = FakeEnterpriseService(), ), appNavigationStateService = FakeAppNavigationStateService(), coroutineScope = backgroundScope, diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultSummaryGroupMessageCreatorTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultSummaryGroupMessageCreatorTest.kt index aae742fa6d..f0831f6fd0 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultSummaryGroupMessageCreatorTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultSummaryGroupMessageCreatorTest.kt @@ -10,6 +10,7 @@ package io.element.android.libraries.push.impl.notifications import android.app.Notification import androidx.core.app.NotificationCompat import com.google.common.truth.Truth.assertThat +import io.element.android.libraries.matrix.test.A_COLOR_INT import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.ui.components.aMatrixUser import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator @@ -47,6 +48,7 @@ class DefaultSummaryGroupMessageCreatorTest { invitationNotifications = emptyList(), simpleNotifications = emptyList(), fallbackNotifications = emptyList(), + color = A_COLOR_INT, ) notificationCreator.createSummaryListNotificationResult.assertions() 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 30c433a513..b8f4364ddb 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 @@ -11,6 +11,7 @@ import com.google.common.truth.Truth.assertThat import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.matrix.test.AN_EVENT_ID +import io.element.android.libraries.matrix.test.A_COLOR_INT import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_SESSION_ID import io.element.android.libraries.push.impl.notifications.fake.FakeActiveNotificationsProvider @@ -53,7 +54,7 @@ class NotificationDataFactoryTest { val expectedNotification = notificationCreator.createRoomInvitationNotificationResult(AN_INVITATION_EVENT) val roomInvitation = listOf(AN_INVITATION_EVENT) - val result = toNotifications(roomInvitation) + val result = toNotifications(roomInvitation, A_COLOR_INT) assertThat(result).isEqualTo( listOf( @@ -73,7 +74,7 @@ class NotificationDataFactoryTest { val expectedNotification = notificationCreator.createRoomInvitationNotificationResult(AN_INVITATION_EVENT) val roomInvitation = listOf(A_SIMPLE_EVENT) - val result = toNotifications(roomInvitation) + val result = toNotifications(roomInvitation, A_COLOR_INT) assertThat(result).isEqualTo( listOf( @@ -93,11 +94,12 @@ class NotificationDataFactoryTest { val events = listOf(A_MESSAGE_EVENT) val expectedNotification = RoomNotification( notification = fakeRoomGroupMessageCreator.createRoomMessage( - MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), - events, - A_ROOM_ID, - FakeImageLoader().getImageLoader(), - null, + currentUser = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), + events = events, + roomId = A_ROOM_ID, + imageLoader = FakeImageLoader().getImageLoader(), + existingNotification = null, + color = A_COLOR_INT, ), roomId = A_ROOM_ID, summaryLine = "A room name: Bob Hello world!", @@ -112,6 +114,7 @@ class NotificationDataFactoryTest { messages = roomWithMessage, currentUser = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), imageLoader = fakeImageLoader.getImageLoader(), + color = A_COLOR_INT, ) assertThat(result.size).isEqualTo(1) @@ -128,6 +131,7 @@ class NotificationDataFactoryTest { messages = redactedRoom, currentUser = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), imageLoader = fakeImageLoader.getImageLoader(), + color = A_COLOR_INT, ) assertThat(result).isEmpty() @@ -145,11 +149,12 @@ class NotificationDataFactoryTest { val withRedactedRemoved = listOf(A_MESSAGE_EVENT.copy(eventId = EventId("\$not-redacted"))) val expectedNotification = RoomNotification( notification = fakeRoomGroupMessageCreator.createRoomMessage( - MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), - withRedactedRemoved, - A_ROOM_ID, - FakeImageLoader().getImageLoader(), - null, + currentUser = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), + events = withRedactedRemoved, + roomId = A_ROOM_ID, + imageLoader = FakeImageLoader().getImageLoader(), + existingNotification = null, + color = A_COLOR_INT, ), roomId = A_ROOM_ID, summaryLine = "A room name: Bob Hello world!", @@ -163,6 +168,7 @@ class NotificationDataFactoryTest { messages = roomWithRedactedMessage, currentUser = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), imageLoader = fakeImageLoader.getImageLoader(), + color = A_COLOR_INT, ) assertThat(result.size).isEqualTo(1) diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRendererTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRendererTest.kt index 8912693bc4..069aaf22ba 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRendererTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationRendererTest.kt @@ -7,6 +7,7 @@ package io.element.android.libraries.push.impl.notifications +import io.element.android.features.enterprise.test.FakeEnterpriseService import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.A_ROOM_ID @@ -58,6 +59,7 @@ class NotificationRendererTest { private val notificationRenderer = NotificationRenderer( notificationDisplayer = notificationDisplayer, notificationDataFactory = notificationDataFactory, + enterpriseService = FakeEnterpriseService(), ) @Test diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/factories/DefaultNotificationCreatorTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/factories/DefaultNotificationCreatorTest.kt index 7786fb261e..06283a76d0 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/factories/DefaultNotificationCreatorTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/factories/DefaultNotificationCreatorTest.kt @@ -16,6 +16,7 @@ import com.google.common.truth.Truth.assertThat import io.element.android.appconfig.NotificationConfig import io.element.android.libraries.core.meta.BuildMeta import io.element.android.libraries.matrix.test.AN_EVENT_ID +import io.element.android.libraries.matrix.test.A_COLOR_INT import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_SESSION_ID import io.element.android.libraries.matrix.test.A_THREAD_ID @@ -50,7 +51,9 @@ class DefaultNotificationCreatorTest { @Test fun `test createDiagnosticNotification`() { val sut = createNotificationCreator() - val result = sut.createDiagnosticNotification() + val result = sut.createDiagnosticNotification( + color = A_COLOR_INT, + ) result.commonAssertions( expectedGroup = null, expectedCategory = NotificationCompat.CATEGORY_STATUS, @@ -72,7 +75,8 @@ class DefaultNotificationCreatorTest { isUpdated = false, timestamp = A_FAKE_TIMESTAMP, cause = null, - ) + ), + color = A_COLOR_INT, ) result.commonAssertions( expectedCategory = null, @@ -97,7 +101,8 @@ class DefaultNotificationCreatorTest { canBeReplaced = false, isRedacted = false, isUpdated = false, - ) + ), + color = A_COLOR_INT, ) result.commonAssertions( expectedCategory = null, @@ -122,7 +127,8 @@ class DefaultNotificationCreatorTest { canBeReplaced = false, isRedacted = false, isUpdated = false, - ) + ), + color = A_COLOR_INT, ) result.commonAssertions( expectedCategory = null, @@ -148,7 +154,8 @@ class DefaultNotificationCreatorTest { isRedacted = false, isUpdated = false, roomName = "roomName", - ) + ), + color = A_COLOR_INT, ) result.commonAssertions( expectedCategory = null, @@ -181,7 +188,8 @@ class DefaultNotificationCreatorTest { isRedacted = false, isUpdated = false, roomName = "roomName", - ) + ), + color = A_COLOR_INT, ) result.commonAssertions( expectedCategory = null, @@ -197,6 +205,7 @@ class DefaultNotificationCreatorTest { compatSummary = "compatSummary", noisy = false, lastMessageTimestamp = 123_456L, + color = A_COLOR_INT, ) result.commonAssertions( expectedGroup = matrixUser.userId.value, @@ -212,6 +221,7 @@ class DefaultNotificationCreatorTest { compatSummary = "compatSummary", noisy = true, lastMessageTimestamp = 123_456L, + color = A_COLOR_INT, ) result.commonAssertions( expectedGroup = matrixUser.userId.value, @@ -240,6 +250,7 @@ class DefaultNotificationCreatorTest { existingNotification = null, imageLoader = FakeImageLoader().getImageLoader(), events = emptyList(), + color = A_COLOR_INT, ) result.commonAssertions() } @@ -266,6 +277,7 @@ class DefaultNotificationCreatorTest { existingNotification = null, imageLoader = FakeImageLoader().getImageLoader(), events = emptyList(), + color = A_COLOR_INT, ) result.commonAssertions() } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationCreator.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationCreator.kt index 3cbed6e8bc..491b0bac33 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationCreator.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeNotificationCreator.kt @@ -9,6 +9,7 @@ package io.element.android.libraries.push.impl.notifications.fake import android.app.Notification import android.graphics.Bitmap +import androidx.annotation.ColorInt import coil3.ImageLoader import io.element.android.libraries.matrix.api.core.ThreadId import io.element.android.libraries.matrix.api.user.MatrixUser @@ -44,22 +45,32 @@ class FakeNotificationCreator( currentUser: MatrixUser, existingNotification: Notification?, imageLoader: ImageLoader, - events: List + events: List, + @ColorInt color: Int, ): Notification { return createMessagesListNotificationResult( listOf(roomInfo, threadId, largeIcon, lastMessageTimestamp, tickerText, currentUser, existingNotification, imageLoader, events) ) } - override fun createRoomInvitationNotification(inviteNotifiableEvent: InviteNotifiableEvent): Notification { + override fun createRoomInvitationNotification( + inviteNotifiableEvent: InviteNotifiableEvent, + @ColorInt color: Int, + ): Notification { return createRoomInvitationNotificationResult(inviteNotifiableEvent) } - override fun createSimpleEventNotification(simpleNotifiableEvent: SimpleNotifiableEvent): Notification { + override fun createSimpleEventNotification( + simpleNotifiableEvent: SimpleNotifiableEvent, + @ColorInt color: Int, + ): Notification { return createSimpleNotificationResult(simpleNotifiableEvent) } - override fun createFallbackNotification(fallbackNotifiableEvent: FallbackNotifiableEvent): Notification { + override fun createFallbackNotification( + fallbackNotifiableEvent: FallbackNotifiableEvent, + @ColorInt color: Int, + ): Notification { return createFallbackNotificationResult(fallbackNotifiableEvent) } @@ -67,12 +78,15 @@ class FakeNotificationCreator( currentUser: MatrixUser, compatSummary: String, noisy: Boolean, - lastMessageTimestamp: Long + lastMessageTimestamp: Long, + @ColorInt color: Int, ): Notification { return createSummaryListNotificationResult(currentUser, compatSummary, noisy, lastMessageTimestamp) } - override fun createDiagnosticNotification(): Notification { + override fun createDiagnosticNotification( + @ColorInt color: Int, + ): Notification { return createDiagnosticNotificationResult() } } 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 fed6e3c7a3..9a0a5fe7ef 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 @@ -7,6 +7,7 @@ package io.element.android.libraries.push.impl.notifications.fake +import androidx.annotation.ColorInt import coil3.ImageLoader import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.push.impl.notifications.NotificationDataFactory @@ -33,31 +34,45 @@ class FakeNotificationDataFactory( List, List, SummaryNotification - > = lambdaRecorder { _, _, _, _, _ -> SummaryNotification.Update(A_NOTIFICATION) }, + > = lambdaRecorder { _, _, _, _, _ -> SummaryNotification.Update(A_NOTIFICATION) }, var inviteToNotificationsResult: LambdaOneParamRecorder, List> = lambdaRecorder { _ -> emptyList() }, var simpleEventToNotificationsResult: LambdaOneParamRecorder, List> = lambdaRecorder { _ -> emptyList() }, var fallbackEventToNotificationsResult: LambdaOneParamRecorder, List> = lambdaRecorder { _ -> emptyList() }, ) : NotificationDataFactory { - override suspend fun toNotifications(messages: List, currentUser: MatrixUser, imageLoader: ImageLoader): List { + override suspend fun toNotifications( + messages: List, + currentUser: MatrixUser, + imageLoader: ImageLoader, + @ColorInt color: Int, + ): List { return messageEventToNotificationsResult(messages, currentUser, imageLoader) } @JvmName("toNotificationInvites") @Suppress("INAPPLICABLE_JVM_NAME") - override fun toNotifications(invites: List): List { + override fun toNotifications( + invites: List, + @ColorInt color: Int, + ): List { return inviteToNotificationsResult(invites) } @JvmName("toNotificationSimpleEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun toNotifications(simpleEvents: List): List { + override fun toNotifications( + simpleEvents: List, + @ColorInt color: Int, + ): List { return simpleEventToNotificationsResult(simpleEvents) } @JvmName("toNotificationFallbackEvents") @Suppress("INAPPLICABLE_JVM_NAME") - override fun toNotifications(fallback: List): List { + override fun toNotifications( + fallback: List, + @ColorInt color: Int, + ): List { return fallbackEventToNotificationsResult(fallback) } @@ -67,6 +82,7 @@ class FakeNotificationDataFactory( invitationNotifications: List, simpleNotifications: List, fallbackNotifications: List, + @ColorInt color: Int, ): SummaryNotification { return summaryToNotificationsResult( currentUser, diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeRoomGroupMessageCreator.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeRoomGroupMessageCreator.kt index c531735a1e..344c77716f 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeRoomGroupMessageCreator.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeRoomGroupMessageCreator.kt @@ -8,6 +8,7 @@ package io.element.android.libraries.push.impl.notifications.fake import android.app.Notification +import androidx.annotation.ColorInt import coil3.ImageLoader import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.user.MatrixUser @@ -19,14 +20,15 @@ import io.element.android.tests.testutils.lambda.lambdaRecorder class FakeRoomGroupMessageCreator( var createRoomMessageResult: LambdaFiveParamsRecorder, RoomId, ImageLoader, Notification?, Notification> = - lambdaRecorder { _, _, _, _, _, -> A_NOTIFICATION } + lambdaRecorder { _, _, _, _, _ -> A_NOTIFICATION } ) : RoomGroupMessageCreator { override suspend fun createRoomMessage( currentUser: MatrixUser, events: List, roomId: RoomId, imageLoader: ImageLoader, - existingNotification: Notification? + existingNotification: Notification?, + @ColorInt color: Int, ): Notification { return createRoomMessageResult(currentUser, events, roomId, imageLoader, existingNotification) } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeSummaryGroupMessageCreator.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeSummaryGroupMessageCreator.kt index ed3ca3027e..bc8a5515c9 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeSummaryGroupMessageCreator.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fake/FakeSummaryGroupMessageCreator.kt @@ -8,6 +8,7 @@ package io.element.android.libraries.push.impl.notifications.fake import android.app.Notification +import androidx.annotation.ColorInt import io.element.android.libraries.matrix.api.user.MatrixUser import io.element.android.libraries.push.impl.notifications.OneShotNotification import io.element.android.libraries.push.impl.notifications.RoomNotification @@ -18,8 +19,7 @@ import io.element.android.tests.testutils.lambda.lambdaRecorder class FakeSummaryGroupMessageCreator( var createSummaryNotificationResult: LambdaFiveParamsRecorder< - MatrixUser, List, List, List, List, Notification - > = + MatrixUser, List, List, List, List, Notification> = lambdaRecorder { _, _, _, _, _ -> A_NOTIFICATION } ) : SummaryGroupMessageCreator { override fun createSummaryNotification( @@ -28,6 +28,7 @@ class FakeSummaryGroupMessageCreator( invitationNotifications: List, simpleNotifications: List, fallbackNotifications: List, + @ColorInt color: Int, ): Notification { return createSummaryNotificationResult( currentUser, diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt index eecb3801fd..7d94fd0082 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt @@ -8,6 +8,8 @@ package io.element.android.libraries.push.impl.troubleshoot import com.google.common.truth.Truth.assertThat +import io.element.android.features.enterprise.test.FakeEnterpriseService +import io.element.android.libraries.matrix.test.A_SESSION_ID import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDisplayer import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState @@ -64,10 +66,12 @@ class NotificationTestTest { private fun createNotificationTest(): NotificationTest { return NotificationTest( + sessionId = A_SESSION_ID, notificationCreator = notificationCreator, notificationDisplayer = fakeNotificationDisplayer, notificationClickHandler = notificationClickHandler, stringProvider = FakeStringProvider(), + enterpriseService = FakeEnterpriseService(), ) } }