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

Unverified Commit feb33417 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Change drawer account selection to depend on uuid only

parent 6edfa57d
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ internal fun DrawerContentPreview() {
        DrawerContent(
            state = DrawerContract.State(
                accounts = persistentListOf(),
                selectedAccount = null,
                selectedAccountUuid = null,
                folders = persistentListOf(),
            ),
            onEvent = {},
@@ -30,7 +30,7 @@ internal fun DrawerContentWithAccountPreview() {
        DrawerContent(
            state = DrawerContract.State(
                accounts = persistentListOf(DISPLAY_ACCOUNT),
                selectedAccount = DISPLAY_ACCOUNT,
                selectedAccountUuid = DISPLAY_ACCOUNT.uuid,
                folders = persistentListOf(),
            ),
            onEvent = {},
@@ -47,7 +47,7 @@ internal fun DrawerContentWithFoldersPreview() {
                accounts = persistentListOf(
                    DISPLAY_ACCOUNT,
                ),
                selectedAccount = null,
                selectedAccountUuid = null,
                folders = persistentListOf(
                    UNIFIED_FOLDER,
                    DISPLAY_FOLDER,
@@ -67,7 +67,7 @@ internal fun DrawerContentWithSelectedFolderPreview() {
                accounts = persistentListOf(
                    DISPLAY_ACCOUNT,
                ),
                selectedAccount = DISPLAY_ACCOUNT,
                selectedAccountUuid = DISPLAY_ACCOUNT.uuid,
                folders = persistentListOf(
                    UNIFIED_FOLDER,
                    DISPLAY_FOLDER,
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ val navigationDrawerModule: Module = module {

    single<UseCase.SyncAccount> {
        SyncAccount(
            accountManager = get(),
            messagingController = get(),
        )
    }
+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package app.k9mail.feature.navigation.drawer.domain
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.DrawerConfig
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayFolder
import app.k9mail.legacy.account.Account
import kotlinx.coroutines.flow.Flow

internal interface DomainContract {
@@ -22,10 +21,10 @@ internal interface DomainContract {
        }

        /**
         * Synchronize the given account.
         * Synchronize the given account uuid.
         */
        fun interface SyncAccount {
            operator fun invoke(account: Account): Flow<Result<Unit>>
            operator fun invoke(accountUuid: String): Flow<Result<Unit>>
        }

        /**
+3 −1
Original line number Diff line number Diff line
@@ -6,4 +6,6 @@ internal data class DisplayAccount(
    val account: Account,
    val unreadMessageCount: Int,
    val starredMessageCount: Int,
)
) {
    val uuid: String = account.uuid
}
+5 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package app.k9mail.feature.navigation.drawer.domain.usecase
import android.content.Context
import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.AccountManager
import app.k9mail.legacy.message.controller.MessagingControllerMailChecker
import app.k9mail.legacy.message.controller.SimpleMessagingListener
import kotlin.coroutines.CoroutineContext
@@ -13,10 +14,11 @@ import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn

internal class SyncAccount(
    private val accountManager: AccountManager,
    private val messagingController: MessagingControllerMailChecker,
    private val coroutineContext: CoroutineContext = Dispatchers.IO,
) : UseCase.SyncAccount {
    override fun invoke(account: Account): Flow<Result<Unit>> = callbackFlow {
    override fun invoke(accountUuid: String): Flow<Result<Unit>> = callbackFlow {
        val listener = object : SimpleMessagingListener() {
            override fun checkMailFinished(context: Context?, account: Account?) {
                trySend(Result.success(Unit))
@@ -24,6 +26,8 @@ internal class SyncAccount(
            }
        }

        val account = accountManager.getAccount(accountUuid)

        messagingController.checkMail(
            account = account,
            ignoreLastCheckedTime = true,
Loading