Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.thunderbird.feature.mail.message.list.domain

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import net.thunderbird.core.common.action.SwipeActions
import net.thunderbird.core.outcome.Outcome
import net.thunderbird.feature.mail.account.api.BaseAccount
import net.thunderbird.feature.account.AccountId
import net.thunderbird.feature.mail.folder.api.FolderServerId
import net.thunderbird.feature.mail.folder.api.RemoteFolder

Expand All @@ -27,12 +28,8 @@ interface DomainContract {
): Outcome<SetAccountFolderOutcome.Success, SetAccountFolderOutcome.Error>
}

fun interface BuildSwipeActions<out TAccount : BaseAccount> {
operator fun invoke(
accountUuids: Set<String>,
isIncomingServerPop3: (TAccount) -> Boolean,
hasArchiveFolder: (TAccount) -> Boolean,
): Map<String, SwipeActions>
fun interface BuildSwipeActions {
operator fun invoke(): StateFlow<Map<AccountId, SwipeActions>>
}
}
}
Expand Down
1 change: 1 addition & 0 deletions feature/mail/message/list/internal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
implementation(projects.feature.mail.message.list.api)

implementation(projects.backend.api)
implementation(projects.core.android.account)
implementation(projects.core.android.common)
implementation(projects.core.logging.api)
implementation(projects.core.outcome)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.thunderbird.feature.mail.message.list.internal

import net.thunderbird.feature.mail.account.api.BaseAccount
import net.thunderbird.feature.mail.message.list.domain.DomainContract
import net.thunderbird.feature.mail.message.list.internal.domain.usecase.BuildSwipeActions
import net.thunderbird.feature.mail.message.list.internal.domain.usecase.CreateArchiveFolder
Expand Down Expand Up @@ -30,7 +29,7 @@ val featureMessageListModule = module {
specialFolderUpdaterFactory = get(),
)
}
factory<DomainContract.UseCase.BuildSwipeActions<BaseAccount>> { parameters ->
factory<DomainContract.UseCase.BuildSwipeActions> {
BuildSwipeActions(
generalSettingsManager = get(),
accountManager = get(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,67 @@
package net.thunderbird.feature.mail.message.list.internal.domain.usecase

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flatMapConcat
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.core.android.account.LegacyAccountManager
import net.thunderbird.core.common.action.SwipeAction
import net.thunderbird.core.common.action.SwipeActions
import net.thunderbird.core.preference.GeneralSettingsManager
import net.thunderbird.feature.mail.account.api.AccountManager
import net.thunderbird.feature.mail.account.api.BaseAccount
import net.thunderbird.feature.account.AccountId
import net.thunderbird.feature.mail.message.list.domain.DomainContract

internal class BuildSwipeActions(
private val generalSettingsManager: GeneralSettingsManager,
private val accountManager: AccountManager<BaseAccount>,
) : DomainContract.UseCase.BuildSwipeActions<BaseAccount> {
private val defaultSwipeActions get() = generalSettingsManager.getConfig().interaction.swipeActions

override fun invoke(
accountUuids: Set<String>,
isIncomingServerPop3: (BaseAccount) -> Boolean,
hasArchiveFolder: (BaseAccount) -> Boolean,
): Map<String, SwipeActions> {
val shouldShowSetupArchiveFolderDialog = generalSettingsManager
.getConfig().display.miscSettings
.shouldShowSetupArchiveFolderDialog
return accountUuids
.mapNotNull { uuid -> accountManager.getAccount(uuid) }
.associate { account ->
account.uuid to SwipeActions(
leftAction = buildSwipeAction(
account = account,
defaultSwipeAction = defaultSwipeActions.leftAction,
isIncomingServerPop3 = isIncomingServerPop3,
hasArchiveFolder = hasArchiveFolder,
shouldShowSetupArchiveFolderDialog = shouldShowSetupArchiveFolderDialog,
),
rightAction = buildSwipeAction(
account = account,
defaultSwipeAction = defaultSwipeActions.rightAction,
isIncomingServerPop3 = isIncomingServerPop3,
hasArchiveFolder = hasArchiveFolder,
shouldShowSetupArchiveFolderDialog = shouldShowSetupArchiveFolderDialog,
),
)
}
}
generalSettingsManager: GeneralSettingsManager,
private val accountManager: LegacyAccountManager,
private val mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + mainDispatcher),
) : DomainContract.UseCase.BuildSwipeActions {
@OptIn(ExperimentalCoroutinesApi::class)
val swipeActions: StateFlow<Map<AccountId, SwipeActions>> = generalSettingsManager.getConfigFlow()
.flatMapConcat { config ->
val defaultSwipeActions = config.interaction.swipeActions
val shouldShowSetupArchiveFolderDialog = config.display.miscSettings.shouldShowSetupArchiveFolderDialog

accountManager
.getAll()
.map { accounts ->
accounts
.associate { account ->
account.id to SwipeActions(
leftAction = buildSwipeAction(
account = account,
defaultSwipeAction = defaultSwipeActions.leftAction,
shouldShowSetupArchiveFolderDialog = shouldShowSetupArchiveFolderDialog,
),
rightAction = buildSwipeAction(
account = account,
defaultSwipeAction = defaultSwipeActions.rightAction,
shouldShowSetupArchiveFolderDialog = shouldShowSetupArchiveFolderDialog,
),
)
}
}
}
.stateIn(
scope = scope,
started = SharingStarted.Eagerly,
initialValue = emptyMap(),
)

@OptIn(ExperimentalCoroutinesApi::class)
override fun invoke(): StateFlow<Map<AccountId, SwipeActions>> = swipeActions

private fun buildSwipeAction(
account: BaseAccount,
account: LegacyAccount,
defaultSwipeAction: SwipeAction,
isIncomingServerPop3: BaseAccount.() -> Boolean,
hasArchiveFolder: BaseAccount.() -> Boolean,
shouldShowSetupArchiveFolderDialog: Boolean,
): SwipeAction = when (defaultSwipeAction) {
SwipeAction.Archive if account.isIncomingServerPop3() -> SwipeAction.ArchiveDisabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import net.thunderbird.backend.api.BackendStorageFactory
import net.thunderbird.core.android.account.LegacyAccountDtoManager
import net.thunderbird.core.common.exception.MessagingException
import net.thunderbird.core.outcome.Outcome
import net.thunderbird.feature.mail.account.api.AccountManager
import net.thunderbird.feature.mail.account.api.BaseAccount
import net.thunderbird.feature.mail.folder.api.FolderType
import net.thunderbird.feature.mail.folder.api.RemoteFolder
Expand All @@ -17,7 +17,7 @@ import net.thunderbird.feature.mail.message.list.domain.SetAccountFolderOutcome
import com.fsck.k9.mail.FolderType as LegacyFolderType

internal class SetArchiveFolder(
private val accountManager: AccountManager<BaseAccount>,
private val accountManager: LegacyAccountDtoManager,
private val backendStorageFactory: BackendStorageFactory<BaseAccount>,
private val specialFolderUpdaterFactory: SpecialFolderUpdater.Factory<BaseAccount>,
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
Expand Down
Loading
Loading