Storing vault filter types in memory (#666)

This commit is contained in:
Ramsey Smith
2024-01-18 12:03:44 -07:00
committed by GitHub
parent ffcdc005c8
commit f505c648c0
4 changed files with 18 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import com.x8bit.bitwarden.data.vault.repository.model.UpdateCipherResult
import com.x8bit.bitwarden.data.vault.repository.model.UpdateSendResult
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
@@ -29,6 +30,14 @@ import kotlinx.coroutines.flow.StateFlow
@Suppress("TooManyFunctions")
interface VaultRepository : VaultLockManager {
/**
* The [VaultFilterType] for the current user.
*
* Note that this does not affect the data provided by the repository and can be used by
* the UI for consistent filtering across screens.
*/
var vaultFilterType: VaultFilterType
/**
* Flow that represents the current vault data.
*

View File

@@ -50,6 +50,7 @@ import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkCollectionLi
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkFolderList
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkSend
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkSendList
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
@@ -110,6 +111,8 @@ class VaultRepositoryImpl(
private val mutableCollectionsStateFlow =
MutableStateFlow<DataState<List<CollectionView>>>(DataState.Loading)
override var vaultFilterType: VaultFilterType = VaultFilterType.AllVaults
override val vaultDataStateFlow: StateFlow<DataState<VaultData>> =
combine(
ciphersStateFlow,

View File

@@ -74,6 +74,8 @@ class VaultViewModel @Inject constructor(
get() = state.vaultFilterData?.selectedVaultFilterType ?: VaultFilterType.AllVaults
init {
// Reset the current vault filter type for the current user
vaultRepository.vaultFilterType = vaultFilterTypeOrDefault
settingsRepository
.getPullToRefreshEnabledFlow()
.map { VaultAction.Internal.PullToRefreshEnableReceive(it) }
@@ -223,6 +225,8 @@ class VaultViewModel @Inject constructor(
private fun handleVaultFilterTypeSelect(action: VaultAction.VaultFilterTypeSelect) {
// Update the current filter
vaultRepository.vaultFilterType = action.vaultFilterType
mutableStateFlow.update {
it.copy(
vaultFilterData = it.vaultFilterData?.copy(

View File

@@ -67,6 +67,7 @@ class VaultViewModelTest : BaseViewModelTest() {
private val vaultRepository: VaultRepository =
mockk {
every { vaultFilterType = any() } returns Unit
every { vaultDataStateFlow } returns mutableVaultDataStateFlow
every { sync() } just runs
every { lockVaultForCurrentUser() } just runs
@@ -392,6 +393,7 @@ class VaultViewModelTest : BaseViewModelTest() {
),
viewModel.stateFlow.value,
)
verify { vaultRepository.vaultFilterType = VaultFilterType.MyVault }
}
@Test