Improve AnnouncementService.

This commit is contained in:
Benoit Marty
2025-10-08 09:45:44 +02:00
parent 2526141067
commit a786f6a5e9
20 changed files with 169 additions and 81 deletions

View File

@@ -19,6 +19,7 @@ android {
setupDependencyInjection()
dependencies {
implementation(projects.features.announcement.api)
implementation(projects.features.migration.api)
implementation(projects.libraries.architecture)
implementation(projects.libraries.androidutils)
@@ -34,5 +35,6 @@ dependencies {
testImplementation(projects.libraries.matrix.test)
testImplementation(projects.libraries.sessionStorage.test)
testImplementation(projects.libraries.preferences.test)
testImplementation(projects.features.announcement.test)
testImplementation(projects.features.rageshake.test)
}

View File

@@ -10,7 +10,8 @@ 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
import io.element.android.features.announcement.api.Announcement
import io.element.android.features.announcement.api.AnnouncementService
/**
* Ensure the new notification sound banner is displayed, but only on application upgrade.
@@ -18,13 +19,13 @@ import io.element.android.libraries.preferences.api.store.AppPreferencesStore
@ContributesIntoSet(AppScope::class)
@Inject
class AppMigration08(
private val appPreferencesStore: AppPreferencesStore,
private val announcementService: AnnouncementService,
) : AppMigration {
override val order: Int = 8
override suspend fun migrate(isFreshInstall: Boolean) {
if (!isFreshInstall) {
appPreferencesStore.setShowNewNotificationSoundBanner(true)
announcementService.showAnnouncement(Announcement.NewNotificationSound)
}
}
}

View File

@@ -8,27 +8,35 @@
package io.element.android.features.migration.impl.migrations
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore
import io.element.android.features.announcement.api.Announcement
import io.element.android.features.rageshake.test.logs.FakeAnnouncementService
import io.element.android.tests.testutils.lambda.lambdaError
import io.element.android.tests.testutils.lambda.lambdaRecorder
import io.element.android.tests.testutils.lambda.value
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)
fun `migration on fresh install should not invoke the AnnouncementService`() = runTest {
val service = FakeAnnouncementService(
showAnnouncementResult = { lambdaError() },
)
val migration = AppMigration08(service)
migration.migrate(isFreshInstall = true)
assertThat(store.showNewNotificationSoundBanner().first()).isFalse()
assertThat(service.announcementsToShowFlow().first()).isEmpty()
}
@Test
fun `migration on upgrade should modify the store`() = runTest {
val store = InMemoryAppPreferencesStore()
assertThat(store.showNewNotificationSoundBanner().first()).isFalse()
val migration = AppMigration08(store)
fun `migration on upgrade should invoke the AnnouncementService`() = runTest {
val showAnnouncementResult = lambdaRecorder<Announcement, Unit> { }
val service = FakeAnnouncementService(
showAnnouncementResult = showAnnouncementResult,
)
val migration = AppMigration08(service)
migration.migrate(isFreshInstall = false)
assertThat(store.showNewNotificationSoundBanner().first()).isTrue()
showAnnouncementResult.assertions().isCalledOnce()
.with(value(Announcement.NewNotificationSound))
}
}