Loading app-common/src/main/kotlin/net/thunderbird/app/common/account/CommonAccountDefaultsProvider.kt +19 −13 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import app.k9mail.legacy.account.ShowPictures import com.fsck.k9.CoreResourceProvider import com.fsck.k9.K9 import net.thunderbird.core.mail.folder.api.SpecialFolderSelection import net.thunderbird.core.preferences.Storage import net.thunderbird.feature.notification.NotificationLight import net.thunderbird.feature.notification.NotificationSettings import net.thunderbird.feature.notification.NotificationVibration Loading @@ -41,7 +42,11 @@ internal class CommonAccountDefaultsProvider( applyLegacyDefaults() } override fun applyOverwrites(account: LegacyAccount) = with(account) { override fun applyOverwrites(account: LegacyAccount, storage: Storage) = with(account) { if (storage.contains("${account.uuid}.notifyNewMail")) { isNotifyNewMail = storage.getBoolean("${account.uuid}.notifyNewMail", false) isNotifySelfNewMail = storage.getBoolean("${account.uuid}.notifySelfNewMail", true) } else { isNotifyNewMail = featureFlagProvider.provide( "email_notification_default".toFeatureFlagKey(), ).whenEnabledOrNot( Loading @@ -56,6 +61,7 @@ internal class CommonAccountDefaultsProvider( onDisabledOrUnavailable = { false }, ) } } @Suppress("LongMethod") private fun LegacyAccount.applyLegacyDefaults() { Loading app-common/src/test/kotlin/net/thunderbird/app/common/account/CommonAccountDefaultsProviderTest.kt +75 −2 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import assertk.assertions.isTrue import com.fsck.k9.CoreResourceProvider import com.fsck.k9.K9 import net.thunderbird.core.mail.folder.api.SpecialFolderSelection import net.thunderbird.core.preferences.Storage import net.thunderbird.feature.notification.NotificationLight import net.thunderbird.feature.notification.NotificationSettings import net.thunderbird.feature.notification.NotificationVibration Loading Loading @@ -147,6 +148,11 @@ class CommonAccountDefaultsProviderTest { uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn false on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { Loading @@ -155,7 +161,7 @@ class CommonAccountDefaultsProviderTest { ) // act testSubject.applyOverwrites(account) testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isFalse() Loading @@ -172,6 +178,73 @@ class CommonAccountDefaultsProviderTest { uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn false on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { FeatureFlagResult.Enabled }, ) // act testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isTrue() assertThat(account.isNotifySelfNewMail).isTrue() } @Suppress("MaxLineLength") @Test fun `applyOverwrites updates account notification values from storage when storage contains isNotifyNewMail value`() { // arrange val resourceProvider = mock<CoreResourceProvider> { on { defaultIdentityDescription() } doReturn "Default Identity" } val account = LegacyAccount( uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn true on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { FeatureFlagResult.Enabled }, ) // act testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isFalse() assertThat(account.isNotifySelfNewMail).isFalse() } @Suppress("MaxLineLength") @Test fun `applyOverwrites updates account notification values from featureFlag values when storage does not contain isNotifyNewMail value`() { // arrange val resourceProvider = mock<CoreResourceProvider> { on { defaultIdentityDescription() } doReturn "Default Identity" } val account = LegacyAccount( uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn false on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { Loading @@ -180,7 +253,7 @@ class CommonAccountDefaultsProviderTest { ) // act testSubject.applyOverwrites(account) testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isTrue() Loading core/android/testing/src/main/kotlin/net/thunderbird/core/android/preferences/InMemoryStoragePersister.kt +8 −3 Original line number Diff line number Diff line package net.thunderbird.core.android.preferences import com.fsck.k9.preferences.Storage import com.fsck.k9.preferences.DefaultStorage import com.fsck.k9.preferences.StorageEditor import com.fsck.k9.preferences.StoragePersister import com.fsck.k9.preferences.StorageUpdater import net.thunderbird.core.preferences.Storage class InMemoryStoragePersister : StoragePersister { private val values = mutableMapOf<String, Any?>() override fun loadValues(): Storage { return Storage(values.mapValues { (_, value) -> value?.toString() ?: "" }) return DefaultStorage( values.mapValues { (_, value) -> value?.toString() ?: "" }, ) } override fun createStorageEditor(storageUpdater: StorageUpdater): StorageEditor { Loading Loading @@ -60,7 +65,7 @@ class InMemoryStoragePersister : StoragePersister { } private fun writeValues(currentStorage: Storage): Storage { return Storage(currentStorage.all - removals + changes) return DefaultStorage(currentStorage.getAll() - removals + changes) } } } core/preferences/src/main/java/net/thunderbird/core/preferences/Storage.kt 0 → 100644 +17 −0 Original line number Diff line number Diff line package net.thunderbird.core.preferences interface Storage { fun isEmpty(): Boolean fun contains(key: String): Boolean fun getAll(): Map<String, String> fun getBoolean(key: String, defValue: Boolean): Boolean fun getInt(key: String, defValue: Int): Int fun getLong(key: String, defValue: Long): Long fun getString(key: String?, defValue: String?): String } legacy/account/build.gradle.kts +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ dependencies { api(projects.mail.common) implementation(projects.core.account) implementation(projects.core.preferences) implementation(projects.core.mail.folder.api) implementation(projects.backend.api) } Loading
app-common/src/main/kotlin/net/thunderbird/app/common/account/CommonAccountDefaultsProvider.kt +19 −13 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import app.k9mail.legacy.account.ShowPictures import com.fsck.k9.CoreResourceProvider import com.fsck.k9.K9 import net.thunderbird.core.mail.folder.api.SpecialFolderSelection import net.thunderbird.core.preferences.Storage import net.thunderbird.feature.notification.NotificationLight import net.thunderbird.feature.notification.NotificationSettings import net.thunderbird.feature.notification.NotificationVibration Loading @@ -41,7 +42,11 @@ internal class CommonAccountDefaultsProvider( applyLegacyDefaults() } override fun applyOverwrites(account: LegacyAccount) = with(account) { override fun applyOverwrites(account: LegacyAccount, storage: Storage) = with(account) { if (storage.contains("${account.uuid}.notifyNewMail")) { isNotifyNewMail = storage.getBoolean("${account.uuid}.notifyNewMail", false) isNotifySelfNewMail = storage.getBoolean("${account.uuid}.notifySelfNewMail", true) } else { isNotifyNewMail = featureFlagProvider.provide( "email_notification_default".toFeatureFlagKey(), ).whenEnabledOrNot( Loading @@ -56,6 +61,7 @@ internal class CommonAccountDefaultsProvider( onDisabledOrUnavailable = { false }, ) } } @Suppress("LongMethod") private fun LegacyAccount.applyLegacyDefaults() { Loading
app-common/src/test/kotlin/net/thunderbird/app/common/account/CommonAccountDefaultsProviderTest.kt +75 −2 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import assertk.assertions.isTrue import com.fsck.k9.CoreResourceProvider import com.fsck.k9.K9 import net.thunderbird.core.mail.folder.api.SpecialFolderSelection import net.thunderbird.core.preferences.Storage import net.thunderbird.feature.notification.NotificationLight import net.thunderbird.feature.notification.NotificationSettings import net.thunderbird.feature.notification.NotificationVibration Loading Loading @@ -147,6 +148,11 @@ class CommonAccountDefaultsProviderTest { uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn false on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { Loading @@ -155,7 +161,7 @@ class CommonAccountDefaultsProviderTest { ) // act testSubject.applyOverwrites(account) testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isFalse() Loading @@ -172,6 +178,73 @@ class CommonAccountDefaultsProviderTest { uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn false on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { FeatureFlagResult.Enabled }, ) // act testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isTrue() assertThat(account.isNotifySelfNewMail).isTrue() } @Suppress("MaxLineLength") @Test fun `applyOverwrites updates account notification values from storage when storage contains isNotifyNewMail value`() { // arrange val resourceProvider = mock<CoreResourceProvider> { on { defaultIdentityDescription() } doReturn "Default Identity" } val account = LegacyAccount( uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn true on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { FeatureFlagResult.Enabled }, ) // act testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isFalse() assertThat(account.isNotifySelfNewMail).isFalse() } @Suppress("MaxLineLength") @Test fun `applyOverwrites updates account notification values from featureFlag values when storage does not contain isNotifyNewMail value`() { // arrange val resourceProvider = mock<CoreResourceProvider> { on { defaultIdentityDescription() } doReturn "Default Identity" } val account = LegacyAccount( uuid = "test-uuid", isSensitiveDebugLoggingEnabled = { false }, ) val storage = mock<Storage> { on { contains("${account.uuid}.notifyNewMail") } doReturn false on { getBoolean("${account.uuid}.notifyNewMail", false) } doReturn false on { getBoolean("${account.uuid}.notifySelfNewMail", false) } doReturn false } val testSubject = CommonAccountDefaultsProvider( resourceProvider = resourceProvider, featureFlagProvider = { Loading @@ -180,7 +253,7 @@ class CommonAccountDefaultsProviderTest { ) // act testSubject.applyOverwrites(account) testSubject.applyOverwrites(account, storage) // assert assertThat(account.isNotifyNewMail).isTrue() Loading
core/android/testing/src/main/kotlin/net/thunderbird/core/android/preferences/InMemoryStoragePersister.kt +8 −3 Original line number Diff line number Diff line package net.thunderbird.core.android.preferences import com.fsck.k9.preferences.Storage import com.fsck.k9.preferences.DefaultStorage import com.fsck.k9.preferences.StorageEditor import com.fsck.k9.preferences.StoragePersister import com.fsck.k9.preferences.StorageUpdater import net.thunderbird.core.preferences.Storage class InMemoryStoragePersister : StoragePersister { private val values = mutableMapOf<String, Any?>() override fun loadValues(): Storage { return Storage(values.mapValues { (_, value) -> value?.toString() ?: "" }) return DefaultStorage( values.mapValues { (_, value) -> value?.toString() ?: "" }, ) } override fun createStorageEditor(storageUpdater: StorageUpdater): StorageEditor { Loading Loading @@ -60,7 +65,7 @@ class InMemoryStoragePersister : StoragePersister { } private fun writeValues(currentStorage: Storage): Storage { return Storage(currentStorage.all - removals + changes) return DefaultStorage(currentStorage.getAll() - removals + changes) } } }
core/preferences/src/main/java/net/thunderbird/core/preferences/Storage.kt 0 → 100644 +17 −0 Original line number Diff line number Diff line package net.thunderbird.core.preferences interface Storage { fun isEmpty(): Boolean fun contains(key: String): Boolean fun getAll(): Map<String, String> fun getBoolean(key: String, defValue: Boolean): Boolean fun getInt(key: String, defValue: Int): Int fun getLong(key: String, defValue: Long): Long fun getString(key: String?, defValue: String?): String }
legacy/account/build.gradle.kts +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ dependencies { api(projects.mail.common) implementation(projects.core.account) implementation(projects.core.preferences) implementation(projects.core.mail.folder.api) implementation(projects.backend.api) }