Show new notification sound banner logic

This commit is contained in:
Benoit Marty
2025-10-07 12:20:24 +02:00
committed by Benoit Marty
parent 71d2c1d9df
commit 4475ed0d37
11 changed files with 150 additions and 2 deletions

View File

@@ -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)
}
}
}

View File

@@ -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()
}
}