Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e8fe151 authored by shamim-emon's avatar shamim-emon
Browse files

Bug-fix : Cannot disable "New mail notifcations"

parent 26ed6f95
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -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
@@ -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(
@@ -56,6 +61,7 @@ internal class CommonAccountDefaultsProvider(
                onDisabledOrUnavailable = { false },
            )
        }
    }

    @Suppress("LongMethod")
    private fun LegacyAccount.applyLegacyDefaults() {
+75 −2
Original line number Diff line number Diff line
@@ -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
@@ -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 = {
@@ -155,7 +161,7 @@ class CommonAccountDefaultsProviderTest {
        )

        // act
        testSubject.applyOverwrites(account)
        testSubject.applyOverwrites(account, storage)

        // assert
        assertThat(account.isNotifyNewMail).isFalse()
@@ -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 = {
@@ -180,7 +253,7 @@ class CommonAccountDefaultsProviderTest {
        )

        // act
        testSubject.applyOverwrites(account)
        testSubject.applyOverwrites(account, storage)

        // assert
        assertThat(account.isNotifyNewMail).isTrue()
+1 −0
Original line number Diff line number Diff line
@@ -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)
}
+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.
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ class Preferences internal constructor(

                    accounts[uuid] = account
                    accountsInOrder.add(account)
                    accountDefaultsProvider.applyOverwrites(account)
                    accountDefaultsProvider.applyOverwrites(account, storage)
                }
            }

Loading