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

Unverified Commit 1ee9a29b authored by Rafael Tonholo's avatar Rafael Tonholo
Browse files

chore: move SpecialFolderUpdater as interface to :core:mail:folder:api module

parent 40c60c9c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ plugins {
}

dependencies {
    implementation(projects.core.account)
    implementation(projects.mail.common)

    testImplementation(projects.core.testing)
+14 −0
Original line number Diff line number Diff line
package net.thunderbird.core.mail.folder.api

import net.thunderbird.core.account.BaseAccount

fun interface SpecialFolderUpdater {
    /**
     * Updates all account's special folders. If POP3, only Inbox is updated.
     */
    fun updateSpecialFolders()

    interface Factory<TAccount : BaseAccount> {
        fun create(account: TAccount): SpecialFolderUpdater
    }
}
+18 −3
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import app.k9mail.legacy.account.LegacyAccount
import app.k9mail.legacy.mailstore.FolderRepository
import com.fsck.k9.Preferences
import net.thunderbird.core.mail.folder.api.SpecialFolderSelection
import net.thunderbird.core.mail.folder.api.SpecialFolderUpdater
import net.thunderbird.feature.folder.api.RemoteFolder

/**
@@ -13,13 +14,13 @@ import net.thunderbird.feature.folder.api.RemoteFolder
 * are marked as [SpecialFolderSelection.MANUAL] but have been deleted from the server.
 */
// TODO: Find a better way to deal with local-only special folders
class SpecialFolderUpdater(
class DefaultSpecialFolderUpdater private constructor(
    private val preferences: Preferences,
    private val folderRepository: FolderRepository,
    private val specialFolderSelectionStrategy: SpecialFolderSelectionStrategy,
    private val account: LegacyAccount,
) {
    fun updateSpecialFolders() {
) : SpecialFolderUpdater {
    override fun updateSpecialFolders() {
        val folders = folderRepository.getRemoteFolders(account)

        updateInbox(folders)
@@ -70,6 +71,7 @@ class SpecialFolderUpdater(
                val specialFolder = specialFolderSelectionStrategy.selectSpecialFolder(folders, type)
                setSpecialFolder(type, specialFolder?.id, SpecialFolderSelection.AUTOMATIC)
            }

            SpecialFolderSelection.MANUAL -> {
                if (folders.none { it.id == getSpecialFolderId(type) }) {
                    setSpecialFolder(type, null, SpecialFolderSelection.MANUAL)
@@ -135,4 +137,17 @@ class SpecialFolderUpdater(
    }

    private fun LegacyAccount.isPop3() = incomingServerSettings.type == Protocols.POP3

    class Factory(
        private val preferences: Preferences,
        private val folderRepository: FolderRepository,
        private val specialFolderSelectionStrategy: SpecialFolderSelectionStrategy,
    ) : SpecialFolderUpdater.Factory<LegacyAccount> {
        override fun create(account: LegacyAccount): SpecialFolderUpdater = DefaultSpecialFolderUpdater(
            preferences = preferences,
            folderRepository = folderRepository,
            specialFolderSelectionStrategy = specialFolderSelectionStrategy,
            account = account,
        )
    }
}
+9 −8
Original line number Diff line number Diff line
@@ -5,23 +5,19 @@ import app.k9mail.legacy.mailstore.FolderRepository
import app.k9mail.legacy.mailstore.MessageStoreManager
import com.fsck.k9.Preferences
import net.thunderbird.backend.api.BackendStorageFactory
import net.thunderbird.core.mail.folder.api.SpecialFolderUpdater

class K9BackendStorageFactory(
    private val preferences: Preferences,
    private val folderRepository: FolderRepository,
    private val messageStoreManager: MessageStoreManager,
    private val specialFolderSelectionStrategy: SpecialFolderSelectionStrategy,
    private val specialFolderUpdaterFactory: SpecialFolderUpdater.Factory<LegacyAccount>,
    private val saveMessageDataCreator: SaveMessageDataCreator,
) : BackendStorageFactory<LegacyAccount> {
    override fun createBackendStorage(account: LegacyAccount): K9BackendStorage {
        val messageStore = messageStoreManager.getMessageStore(account)
        val folderSettingsProvider = FolderSettingsProvider(preferences, account)
        val specialFolderUpdater = SpecialFolderUpdater(
            preferences,
            folderRepository,
            specialFolderSelectionStrategy,
            account,
        )
        val specialFolderUpdater = specialFolderUpdaterFactory.create(account)
        val specialFolderListener = SpecialFolderBackendFoldersRefreshListener(specialFolderUpdater)
        val autoExpandFolderListener = AutoExpandFolderBackendFoldersRefreshListener(
            preferences,
@@ -29,6 +25,11 @@ class K9BackendStorageFactory(
            folderRepository,
        )
        val listeners = listOf(specialFolderListener, autoExpandFolderListener)
        return K9BackendStorage(messageStore, folderSettingsProvider, saveMessageDataCreator, listeners)
        return K9BackendStorage(
            messageStore = messageStore,
            folderSettingsProvider = folderSettingsProvider,
            saveMessageDataCreator = saveMessageDataCreator,
            listeners = listeners,
        )
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import com.fsck.k9.message.extractors.AttachmentCounter
import com.fsck.k9.message.extractors.MessageFulltextCreator
import com.fsck.k9.message.extractors.MessagePreviewCreator
import net.thunderbird.backend.api.BackendStorageFactory
import net.thunderbird.core.mail.folder.api.SpecialFolderUpdater
import org.koin.dsl.module

val mailStoreModule = module {
@@ -18,12 +19,19 @@ val mailStoreModule = module {
    single { MessageViewInfoExtractorFactory(get(), get(), get()) }
    single<StorageFilesProviderFactory> { AndroidStorageFilesProviderFactory(context = get()) }
    single { SpecialFolderSelectionStrategy() }
    factory<SpecialFolderUpdater.Factory<*>> {
        DefaultSpecialFolderUpdater.Factory(
            folderRepository = get(),
            specialFolderSelectionStrategy = get(),
            preferences = get(),
        )
    }
    single {
        K9BackendStorageFactory(
            preferences = get(),
            folderRepository = get(),
            messageStoreManager = get(),
            specialFolderSelectionStrategy = get(),
            specialFolderUpdaterFactory = get(),
            saveMessageDataCreator = get(),
        )
    }