diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomListContentView.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomListContentView.kt index 2845a79b8e..34d036b204 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomListContentView.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomListContentView.kt @@ -251,6 +251,12 @@ private fun RoomsViewList( item { BatteryOptimizationBanner(state = state.batteryOptimizationState) } + } else if (state.showNewNotificationSoundBanner) { + item { + NewNotificationSoundBanner( + onDismissClick = { updatedEventSink(RoomListEvents.DismissNewNotificationSoundBanner) }, + ) + } } } diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListContentStateProvider.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListContentStateProvider.kt index a421c239cb..0cc2fd6282 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListContentStateProvider.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListContentStateProvider.kt @@ -26,17 +26,22 @@ open class RoomListContentStateProvider : PreviewParameterProvider = aRoomListRoomSummaryList(), fullScreenIntentPermissionsState: FullScreenIntentPermissionsState = aFullScreenIntentPermissionsState(), batteryOptimizationState: BatteryOptimizationState = aBatteryOptimizationState(), seenRoomInvites: Set = emptySet(), ) = RoomListContentState.Rooms( securityBannerState = securityBannerState, + showNewNotificationSoundBanner = showNewNotificationSoundBanner, fullScreenIntentPermissionsState = fullScreenIntentPermissionsState, batteryOptimizationState = batteryOptimizationState, summaries = summaries, diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListEvents.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListEvents.kt index 02df2cac35..52da613be7 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListEvents.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListEvents.kt @@ -14,6 +14,7 @@ sealed interface RoomListEvents { data class UpdateVisibleRange(val range: IntRange) : RoomListEvents data object DismissRequestVerificationPrompt : RoomListEvents data object DismissBanner : RoomListEvents + data object DismissNewNotificationSoundBanner : RoomListEvents data object ToggleSearchResults : RoomListEvents data class ShowContextMenu(val roomSummary: RoomListRoomSummary) : RoomListEvents diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt index 7b51e4797e..72a666a124 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt @@ -98,6 +98,7 @@ class RoomListPresenter( } var securityBannerDismissed by rememberSaveable { mutableStateOf(false) } + val showNewNotificationSoundBanner by appPreferencesStore.showNewNotificationSoundBanner().collectAsState(false) // Avatar indicator val hideInvitesAvatar by client.rememberHideInvitesAvatar() @@ -112,6 +113,9 @@ class RoomListPresenter( } RoomListEvents.DismissRequestVerificationPrompt -> securityBannerDismissed = true RoomListEvents.DismissBanner -> securityBannerDismissed = true + RoomListEvents.DismissNewNotificationSoundBanner -> coroutineScope.launch { + appPreferencesStore.setShowNewNotificationSoundBanner(false) + } RoomListEvents.ToggleSearchResults -> searchState.eventSink(RoomListSearchEvents.ToggleSearchVisibility) is RoomListEvents.ShowContextMenu -> { coroutineScope.showContextMenu(event, contextMenu) @@ -141,7 +145,10 @@ class RoomListPresenter( } } - val contentState = roomListContentState(securityBannerDismissed) + val contentState = roomListContentState( + securityBannerDismissed, + showNewNotificationSoundBanner, + ) val canReportRoom by produceState(false) { value = client.canReportRoom() } @@ -197,6 +204,7 @@ class RoomListPresenter( @Composable private fun roomListContentState( securityBannerDismissed: Boolean, + showNewNotificationSoundBanner: Boolean, ): RoomListContentState { val roomSummaries by produceState(initialValue = AsyncData.Loading()) { roomListDataSource.allRooms.collect { value = AsyncData.Success(it) } @@ -215,11 +223,14 @@ class RoomListPresenter( val seenRoomInvites by remember { seenInvitesStore.seenRoomIds() }.collectAsState(emptySet()) val securityBannerState by rememberSecurityBannerState(securityBannerDismissed) return when { - showEmpty -> RoomListContentState.Empty(securityBannerState = securityBannerState) + showEmpty -> RoomListContentState.Empty( + securityBannerState = securityBannerState, + ) showSkeleton -> RoomListContentState.Skeleton(count = 16) else -> { RoomListContentState.Rooms( securityBannerState = securityBannerState, + showNewNotificationSoundBanner = showNewNotificationSoundBanner, fullScreenIntentPermissionsState = fullScreenIntentPermissionsPresenter.present(), batteryOptimizationState = batteryOptimizationPresenter.present(), summaries = roomSummaries.dataOrNull().orEmpty().toPersistentList(), diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListState.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListState.kt index 4a301f0897..80cd6394e8 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListState.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListState.kt @@ -69,6 +69,7 @@ sealed interface RoomListContentState { val securityBannerState: SecurityBannerState, val fullScreenIntentPermissionsState: FullScreenIntentPermissionsState, val batteryOptimizationState: BatteryOptimizationState, + val showNewNotificationSoundBanner: Boolean, val summaries: ImmutableList, val seenRoomInvites: ImmutableSet, ) : RoomListContentState diff --git a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt index bde004cf82..041c43dab0 100644 --- a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt +++ b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt @@ -75,6 +75,7 @@ import io.element.android.tests.testutils.lambda.value import io.element.android.tests.testutils.test import io.element.android.tests.testutils.testCoroutineDispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.advanceTimeBy import kotlinx.coroutines.test.runTest @@ -593,6 +594,38 @@ class RoomListPresenterTest { } } + @Test + fun `present - notification sound banner`() = runTest { + val subscribeToVisibleRoomsLambda = lambdaRecorder { _: List -> } + val roomListService = FakeRoomListService(subscribeToVisibleRoomsLambda = subscribeToVisibleRoomsLambda) + val matrixClient = FakeMatrixClient( + roomListService = roomListService, + ) + val roomSummary = aRoomSummary( + currentUserMembership = CurrentUserMembership.INVITED + ) + roomListService.postAllRoomsLoadingState(RoomList.LoadingState.Loaded(1)) + roomListService.postAllRooms(listOf(roomSummary)) + val store = InMemoryAppPreferencesStore() + val presenter = createRoomListPresenter( + client = matrixClient, + appPreferencesStore = store, + ) + presenter.test { + assertThat(store.showNewNotificationSoundBanner().first()).isFalse() + skipItems(1) + val state = awaitItem() + assertThat(state.contentAsRooms().showNewNotificationSoundBanner).isFalse() + store.setShowNewNotificationSoundBanner(true) + assertThat(store.showNewNotificationSoundBanner().first()).isTrue() + assertThat(awaitItem().contentAsRooms().showNewNotificationSoundBanner).isTrue() + state.eventSink(RoomListEvents.DismissNewNotificationSoundBanner) + assertThat(awaitItem().contentAsRooms().showNewNotificationSoundBanner).isFalse() + // Ensure store has been updated + assertThat(store.showNewNotificationSoundBanner().first()).isFalse() + } + } + private fun TestScope.createRoomListPresenter( client: MatrixClient = FakeMatrixClient(), leaveRoomState: LeaveRoomState = aLeaveRoomState(), diff --git a/features/migration/impl/src/main/kotlin/io/element/android/features/migration/impl/migrations/AppMigration08.kt b/features/migration/impl/src/main/kotlin/io/element/android/features/migration/impl/migrations/AppMigration08.kt new file mode 100644 index 0000000000..df1a508a6d --- /dev/null +++ b/features/migration/impl/src/main/kotlin/io/element/android/features/migration/impl/migrations/AppMigration08.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.migration.impl.migrations + +import dev.zacsweers.metro.AppScope +import dev.zacsweers.metro.ContributesIntoSet +import dev.zacsweers.metro.Inject +import io.element.android.libraries.preferences.api.store.AppPreferencesStore + +/** + * Ensure the new notification sound banner is displayed, but only on application upgrade. + */ +@ContributesIntoSet(AppScope::class) +@Inject +class AppMigration08( + private val appPreferencesStore: AppPreferencesStore, +) : AppMigration { + override val order: Int = 8 + + override suspend fun migrate(isFreshInstall: Boolean) { + if (!isFreshInstall) { + appPreferencesStore.setShowNewNotificationSoundBanner(true) + } + } +} diff --git a/features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/migrations/AppMigration08Test.kt b/features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/migrations/AppMigration08Test.kt new file mode 100644 index 0000000000..f908a10bcc --- /dev/null +++ b/features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/migrations/AppMigration08Test.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.migration.impl.migrations + +import com.google.common.truth.Truth.assertThat +import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class AppMigration08Test { + @Test + fun `migration on fresh install should not modify the store`() = runTest { + val store = InMemoryAppPreferencesStore() + assertThat(store.showNewNotificationSoundBanner().first()).isFalse() + val migration = AppMigration08(store) + migration.migrate(isFreshInstall = true) + assertThat(store.showNewNotificationSoundBanner().first()).isFalse() + } + + @Test + fun `migration on upgrade should modify the store`() = runTest { + val store = InMemoryAppPreferencesStore() + assertThat(store.showNewNotificationSoundBanner().first()).isFalse() + val migration = AppMigration08(store) + migration.migrate(isFreshInstall = false) + assertThat(store.showNewNotificationSoundBanner().first()).isTrue() + } +} diff --git a/libraries/preferences/api/src/main/kotlin/io/element/android/libraries/preferences/api/store/AppPreferencesStore.kt b/libraries/preferences/api/src/main/kotlin/io/element/android/libraries/preferences/api/store/AppPreferencesStore.kt index 7e47785088..18d7d4f092 100644 --- a/libraries/preferences/api/src/main/kotlin/io/element/android/libraries/preferences/api/store/AppPreferencesStore.kt +++ b/libraries/preferences/api/src/main/kotlin/io/element/android/libraries/preferences/api/store/AppPreferencesStore.kt @@ -37,5 +37,8 @@ interface AppPreferencesStore { suspend fun setTracingLogPacks(targets: Set) fun getTracingLogPacksFlow(): Flow> + suspend fun setShowNewNotificationSoundBanner(show: Boolean) + fun showNewNotificationSoundBanner(): Flow + suspend fun reset() } diff --git a/libraries/preferences/impl/src/main/kotlin/io/element/android/libraries/preferences/impl/store/DefaultAppPreferencesStore.kt b/libraries/preferences/impl/src/main/kotlin/io/element/android/libraries/preferences/impl/store/DefaultAppPreferencesStore.kt index b3890a8a7d..984503e673 100644 --- a/libraries/preferences/impl/src/main/kotlin/io/element/android/libraries/preferences/impl/store/DefaultAppPreferencesStore.kt +++ b/libraries/preferences/impl/src/main/kotlin/io/element/android/libraries/preferences/impl/store/DefaultAppPreferencesStore.kt @@ -30,6 +30,7 @@ private val hideInviteAvatarsKey = booleanPreferencesKey("hideInviteAvatars") private val timelineMediaPreviewValueKey = stringPreferencesKey("timelineMediaPreviewValue") private val logLevelKey = stringPreferencesKey("logLevel") private val traceLogPacksKey = stringPreferencesKey("traceLogPacks") +private val showNewNotificationSoundBannerKey = booleanPreferencesKey("showNewNotificationSoundBanner") @ContributesBinding(AppScope::class) @Inject @@ -145,6 +146,19 @@ class DefaultAppPreferencesStore( } } + override suspend fun setShowNewNotificationSoundBanner(show: Boolean) { + store.edit { prefs -> + prefs[showNewNotificationSoundBannerKey] = show + } + } + + override fun showNewNotificationSoundBanner(): Flow { + return store.data.map { prefs -> + // Default is false, but a migration will set it to true on application upgrade (see AppMigration08) + prefs[showNewNotificationSoundBannerKey] ?: false + } + } + override suspend fun reset() { store.edit { it.clear() } } diff --git a/libraries/preferences/test/src/main/kotlin/io/element/android/libraries/preferences/test/InMemoryAppPreferencesStore.kt b/libraries/preferences/test/src/main/kotlin/io/element/android/libraries/preferences/test/InMemoryAppPreferencesStore.kt index d0ee298a66..a601eb6b1d 100644 --- a/libraries/preferences/test/src/main/kotlin/io/element/android/libraries/preferences/test/InMemoryAppPreferencesStore.kt +++ b/libraries/preferences/test/src/main/kotlin/io/element/android/libraries/preferences/test/InMemoryAppPreferencesStore.kt @@ -22,6 +22,7 @@ class InMemoryAppPreferencesStore( theme: String? = null, logLevel: LogLevel = LogLevel.INFO, traceLockPacks: Set = emptySet(), + showNewNotificationSoundBanner: Boolean = false, ) : AppPreferencesStore { private val isDeveloperModeEnabled = MutableStateFlow(isDeveloperModeEnabled) private val customElementCallBaseUrl = MutableStateFlow(customElementCallBaseUrl) @@ -30,6 +31,7 @@ class InMemoryAppPreferencesStore( private val tracingLogPacks = MutableStateFlow(traceLockPacks) private val hideInviteAvatars = MutableStateFlow(hideInviteAvatars) private val timelineMediaPreviewValue = MutableStateFlow(timelineMediaPreviewValue) + private val showNewNotificationSoundBanner = MutableStateFlow(showNewNotificationSoundBanner) override suspend fun setDeveloperModeEnabled(enabled: Boolean) { isDeveloperModeEnabled.value = enabled @@ -91,6 +93,14 @@ class InMemoryAppPreferencesStore( return tracingLogPacks } + override suspend fun setShowNewNotificationSoundBanner(show: Boolean) { + showNewNotificationSoundBanner.value = show + } + + override fun showNewNotificationSoundBanner(): Flow { + return showNewNotificationSoundBanner + } + override suspend fun reset() { // No op }