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

Unverified Commit 8e2656e4 authored by Rafael Tonholo's avatar Rafael Tonholo Committed by GitHub
Browse files

Merge pull request #9137 from shamim-emon/fix-issue-9135

Fixed Bug - Cannot disable New mail notifcations
parents a8fb859a 1e8fe151
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()
+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 {
@@ -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)
        }
    }
}
+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
}
+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)
}
Loading