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 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) } legacy/account/src/main/java/app/k9mail/legacy/account/AccountDefaultsProvider.kt +3 −1 Original line number Diff line number Diff line package app.k9mail.legacy.account import net.thunderbird.core.preferences.Storage interface AccountDefaultsProvider { /** * Apply default values to the account. Loading @@ -13,7 +15,7 @@ interface AccountDefaultsProvider { * * This method should be called when updating an existing account. */ fun applyOverwrites(account: LegacyAccount) fun applyOverwrites(account: LegacyAccount, storage: Storage) companion object { const val DEFAULT_MAXIMUM_AUTO_DOWNLOAD_MESSAGE_SIZE = 131072 Loading legacy/core/src/main/java/com/fsck/k9/Preferences.kt +1 −1 Original line number Diff line number Diff line Loading @@ -91,7 +91,7 @@ class Preferences internal constructor( accounts[uuid] = account accountsInOrder.add(account) accountDefaultsProvider.applyOverwrites(account) accountDefaultsProvider.applyOverwrites(account, storage) } } Loading 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
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) }
legacy/account/src/main/java/app/k9mail/legacy/account/AccountDefaultsProvider.kt +3 −1 Original line number Diff line number Diff line package app.k9mail.legacy.account import net.thunderbird.core.preferences.Storage interface AccountDefaultsProvider { /** * Apply default values to the account. Loading @@ -13,7 +15,7 @@ interface AccountDefaultsProvider { * * This method should be called when updating an existing account. */ fun applyOverwrites(account: LegacyAccount) fun applyOverwrites(account: LegacyAccount, storage: Storage) companion object { const val DEFAULT_MAXIMUM_AUTO_DOWNLOAD_MESSAGE_SIZE = 131072 Loading
legacy/core/src/main/java/com/fsck/k9/Preferences.kt +1 −1 Original line number Diff line number Diff line Loading @@ -91,7 +91,7 @@ class Preferences internal constructor( accounts[uuid] = account accountsInOrder.add(account) accountDefaultsProvider.applyOverwrites(account) accountDefaultsProvider.applyOverwrites(account, storage) } } Loading