BIT-1715: Fix autofill account-switching data loading error (#965)

This commit is contained in:
Brian Yencho
2024-02-06 12:56:58 -06:00
committed by Álison Fernandes
parent ce9dff7ab2
commit 390411ded7
5 changed files with 139 additions and 1 deletions

View File

@@ -50,4 +50,9 @@ interface VaultLockManager {
initUserCryptoMethod: InitUserCryptoMethod,
organizationKeys: Map<String, String>?,
): VaultUnlockResult
/**
* Suspends until the vault for the given [userId] is unlocked.
*/
suspend fun waitUntilUnlocked(userId: String)
}

View File

@@ -176,6 +176,17 @@ class VaultLockManagerImpl(
.onCompletion { setVaultToNotUnlocking(userId = userId) }
.first()
override suspend fun waitUntilUnlocked(userId: String) {
vaultUnlockDataStateFlow
.map { vaultUnlockDataList ->
// Get the list of currently-unlocked vaults and map them to user IDs.
vaultUnlockDataList
.filter { it.status == VaultUnlockData.Status.UNLOCKED }
.map { it.userId }
}
.first { unlockedUserIds -> userId in unlockedUserIds }
}
/**
* Increments the stored invalid unlock count for the given [userId] and automatically logs out
* if this new value is greater than [MAXIMUM_INVALID_UNLOCK_ATTEMPTS].

View File

@@ -1289,6 +1289,7 @@ class VaultRepositoryImpl(
mutableCiphersStateFlow.value = DataState.Loading
}
.map {
waitUntilUnlocked(userId = userId)
vaultSdkSource
.decryptCipherList(
userId = userId,
@@ -1321,6 +1322,7 @@ class VaultRepositoryImpl(
.getFolders(userId = userId)
.onStart { mutableFoldersStateFlow.value = DataState.Loading }
.map {
waitUntilUnlocked(userId = userId)
vaultSdkSource
.decryptFolderList(
userId = userId,
@@ -1340,6 +1342,7 @@ class VaultRepositoryImpl(
.getCollections(userId = userId)
.onStart { mutableCollectionsStateFlow.value = DataState.Loading }
.map {
waitUntilUnlocked(userId = userId)
vaultSdkSource
.decryptCollectionList(
userId = userId,
@@ -1363,6 +1366,7 @@ class VaultRepositoryImpl(
.getSends(userId = userId)
.onStart { mutableSendDataStateFlow.value = DataState.Loading }
.map {
waitUntilUnlocked(userId = userId)
vaultSdkSource
.decryptSendList(
userId = userId,