Fix multi-account announcement never being displayed

This commit is contained in:
Benoit Marty
2026-10-06 09:33:33 +02:00
committed by Benoit Marty
parent 86e72ac11e
commit 72f4c4f897
3 changed files with 12 additions and 9 deletions
@@ -40,11 +40,11 @@ class DefaultAnnouncementStore(
// NOT replay on first launch.
// - Fullscreen.Space is disabled
// - NewNotificationSound is opted in by AppMigration08
// - MultiAccount is opted in by AppMigration11
// - MultiAccount is NeverShown by default, AppMigration11 sets it to Show or Shown.
val defaultStatus = when (announcement) {
Announcement.Fullscreen.Space -> AnnouncementStatus.Shown
Announcement.NewNotificationSound -> AnnouncementStatus.Shown
Announcement.MultiAccount -> AnnouncementStatus.Shown
Announcement.MultiAccount -> AnnouncementStatus.NeverShown
}
return store.data.map { prefs ->
val ordinal = prefs[key] ?: defaultStatus.ordinal
@@ -16,6 +16,7 @@ import io.element.android.libraries.sessionstorage.api.SessionStore
/**
* Ensure the multi-account announcement is displayed, but only on application upgrade,
* and only if the user does not already have several accounts.
* In the other cases, mark the announcement as already shown.
*/
@ContributesIntoSet(AppScope::class)
class AppMigration11(
@@ -25,10 +26,8 @@ class AppMigration11(
override val order: Int = 11
override suspend fun migrate(isFreshInstall: Boolean) {
if (isFreshInstall) return
if (sessionStore.getAllSessions().size > 1) {
// The user already uses several accounts, no need to announce the feature
if (isFreshInstall || sessionStore.getAllSessions().size > 1) {
// New users, or users who already have several accounts, do not need to be informed about the feature
announcementService.onAnnouncementDismissed(Announcement.MultiAccount)
} else {
announcementService.showAnnouncement(Announcement.MultiAccount)
@@ -18,14 +18,18 @@ import org.junit.Test
class AppMigration11Test {
@Test
fun `migration on fresh install should not invoke the AnnouncementService`() = runTest {
val service = FakeAnnouncementService()
fun `migration on fresh install should mark the announcement as dismissed`() = runTest {
val onAnnouncementDismissedResult = lambdaRecorder<Announcement, Unit> { }
val service = FakeAnnouncementService(
onAnnouncementDismissedResult = onAnnouncementDismissedResult,
)
val migration = AppMigration11(
sessionStore = InMemorySessionStore(initialList = listOf(aSessionData())),
announcementService = service,
)
// FakeAnnouncementService lambdas throw by default
migration.migrate(isFreshInstall = true)
onAnnouncementDismissedResult.assertions().isCalledOnce()
.with(value(Announcement.MultiAccount))
}
@Test