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

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

Change SyncMail to SyncAccount use case

parent de81e257
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase
import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayAccounts
import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayFoldersForAccount
import app.k9mail.feature.navigation.drawer.domain.usecase.GetDrawerConfig
import app.k9mail.feature.navigation.drawer.domain.usecase.SyncMail
import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAccount
import app.k9mail.feature.navigation.drawer.legacy.AccountsViewModel
import app.k9mail.feature.navigation.drawer.legacy.FoldersViewModel
import app.k9mail.feature.navigation.drawer.ui.DrawerViewModel
@@ -37,8 +37,8 @@ val navigationDrawerModule: Module = module {
        )
    }

    single<UseCase.SyncMail> {
        SyncMail(
    single<UseCase.SyncAccount> {
        SyncAccount(
            messagingController = get(),
        )
    }
@@ -66,7 +66,7 @@ val navigationDrawerModule: Module = module {
            getDrawerConfig = get(),
            getDisplayAccounts = get(),
            getDisplayFoldersForAccount = get(),
            syncMail = get(),
            syncAccount = get(),
        )
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -22,12 +22,11 @@ internal interface DomainContract {
        }

        /**
         * Synchronize mail for the given account.
         *
         * Account can be null to synchronize unified inbox or account list.
         * Synchronize the given account.
         */
        fun interface SyncMail {
            operator fun invoke(account: Account?): Flow<Result<Unit>>
        fun interface SyncAccount {
            operator fun invoke(account: Account): Flow<Result<Unit>>
        }
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -12,11 +12,11 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn

internal class SyncMail(
internal class SyncAccount(
    private val messagingController: MessagingControllerMailChecker,
    private val coroutineContext: CoroutineContext = Dispatchers.IO,
) : UseCase.SyncMail {
    override fun invoke(account: Account?): Flow<Result<Unit>> = callbackFlow {
) : UseCase.SyncAccount {
    override fun invoke(account: Account): Flow<Result<Unit>> = callbackFlow {
        val listener = object : SimpleMessagingListener() {
            override fun checkMailFinished(context: Context?, account: Account?) {
                trySend(Result.success(Unit))
+10 −8
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ internal class DrawerViewModel(
    private val getDrawerConfig: UseCase.GetDrawerConfig,
    private val getDisplayAccounts: UseCase.GetDisplayAccounts,
    private val getDisplayFoldersForAccount: UseCase.GetDisplayFoldersForAccount,
    private val syncMail: UseCase.SyncMail,
    private val syncAccount: UseCase.SyncAccount,
    initialState: State = State(),
) : BaseViewModel<State, Event, Effect>(
    initialState = initialState,
@@ -157,12 +157,13 @@ internal class DrawerViewModel(
    }

    private fun refresh() {
        if (state.value.selectedAccount != null) {
            viewModelScope.launch {
                updateState {
                    it.copy(isLoading = true)
                }

            syncMail(state.value.selectedAccount?.account).collect()
                state.value.selectedAccount?.account?.let { syncAccount(it).collect() }

                updateState {
                    it.copy(isLoading = false)
@@ -170,6 +171,7 @@ internal class DrawerViewModel(
            }
        }
    }
}

/**
 * Delay before closing the drawer to avoid the drawer being closed immediately and give time
+19 −0
Original line number Diff line number Diff line
package app.k9mail.feature.navigation.drawer.domain.usecase

import app.k9mail.legacy.account.Account
import app.k9mail.legacy.message.controller.MessagingControllerMailChecker
import app.k9mail.legacy.message.controller.MessagingListener

internal class FakeMessagingControllerMailChecker(
    private val listenerExecutor: (MessagingListener?) -> Unit = {},
) : MessagingControllerMailChecker {
    override fun checkMail(
        account: Account?,
        ignoreLastCheckedTime: Boolean,
        useManualWakeLock: Boolean,
        notify: Boolean,
        listener: MessagingListener?,
    ) {
        listenerExecutor(listener)
    }
}
Loading