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

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

refactor(account): change LegacyAccountWrapperManger to use the new id

parent ece8348f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ internal class DefaultAccountProfileLocalDataSource(
) : AccountProfileLocalDataSource {

    override fun getById(accountId: AccountId): Flow<AccountProfile?> {
        return accountManager.getById(accountId.asRaw())
        return accountManager.getById(accountId)
            .map { account ->
                account?.let { dto ->
                    dataMapper.toDomain(dto.profile)
@@ -24,7 +24,7 @@ internal class DefaultAccountProfileLocalDataSource(
    }

    override suspend fun update(accountProfile: AccountProfile) {
        val currentAccount = accountManager.getById(accountProfile.id.asRaw())
        val currentAccount = accountManager.getById(accountProfile.id)
            .firstOrNull() ?: return

        val accountProfile = dataMapper.toDto(accountProfile)
+3 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import kotlinx.coroutines.flow.map
import net.thunderbird.core.android.account.AccountManager
import net.thunderbird.core.android.account.LegacyAccountWrapper
import net.thunderbird.core.android.account.LegacyAccountWrapperManager
import net.thunderbird.feature.account.AccountId
import net.thunderbird.feature.account.storage.legacy.mapper.DefaultLegacyAccountWrapperDataMapper

internal class DefaultLegacyAccountWrapperManager(
@@ -21,8 +22,8 @@ internal class DefaultLegacyAccountWrapperManager(
            }
    }

    override fun getById(id: String): Flow<LegacyAccountWrapper?> {
        return accountManager.getAccountFlow(id).map { account ->
    override fun getById(id: AccountId): Flow<LegacyAccountWrapper?> {
        return accountManager.getAccountFlow(id.asRaw()).map { account ->
            account?.let {
                accountDataMapper.toDomain(it)
            }
+4 −3
Original line number Diff line number Diff line
@@ -7,21 +7,22 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import net.thunderbird.core.android.account.LegacyAccountWrapper
import net.thunderbird.core.android.account.LegacyAccountWrapperManager
import net.thunderbird.feature.account.AccountId

internal class FakeLegacyAccountWrapperManager(
    initialAccounts: List<LegacyAccountWrapper> = emptyList(),
) : LegacyAccountWrapperManager {

    private val accountsState = MutableStateFlow<List<LegacyAccountWrapper>>(
    private val accountsState = MutableStateFlow(
        initialAccounts,
    )
    private val accounts: StateFlow<List<LegacyAccountWrapper>> = accountsState

    override fun getAll(): Flow<List<LegacyAccountWrapper>> = accounts

    override fun getById(id: String): Flow<LegacyAccountWrapper?> = accounts
    override fun getById(id: AccountId): Flow<LegacyAccountWrapper?> = accounts
        .map { list ->
            list.find { it.uuid == id }
            list.find { it.id == id }
        }

    override suspend fun update(account: LegacyAccountWrapper) {
+2 −1
Original line number Diff line number Diff line
package net.thunderbird.core.android.account

import kotlinx.coroutines.flow.Flow
import net.thunderbird.feature.account.AccountId

interface LegacyAccountWrapperManager {
    fun getAll(): Flow<List<LegacyAccountWrapper>>

    fun getById(id: String): Flow<LegacyAccountWrapper?>
    fun getById(id: AccountId): Flow<LegacyAccountWrapper?>

    suspend fun update(account: LegacyAccountWrapper)
}