mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 17:36:01 +03:00
Use isolated per-item scopes for TOTP flows (#1384)
This commit is contained in:
parent
217de5c8ba
commit
0149da361c
1 changed files with 7 additions and 1 deletions
|
@ -8,6 +8,7 @@ import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
|||
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
|
||||
import com.x8bit.bitwarden.data.vault.manager.model.VerificationCodeItem
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
@ -80,6 +81,10 @@ class TotpCodeManagerImpl(
|
|||
val cipherId = cipher?.id ?: return MutableStateFlow(DataState.Loaded(null))
|
||||
|
||||
return mutableVerificationCodeStateFlowMap.getOrPut(cipher) {
|
||||
// Define a per-item scope so that we can clear the Flow from the scope when it is
|
||||
// no longer needed.
|
||||
val itemScope = CoroutineScope(dispatcherManager.unconfined)
|
||||
|
||||
flow<DataState<VerificationCodeItem?>> {
|
||||
val totpCode = cipher
|
||||
.login
|
||||
|
@ -139,9 +144,10 @@ class TotpCodeManagerImpl(
|
|||
}
|
||||
.onCompletion {
|
||||
mutableVerificationCodeStateFlowMap.remove(cipher)
|
||||
itemScope.cancel()
|
||||
}
|
||||
.stateIn(
|
||||
scope = unconfinedScope,
|
||||
scope = itemScope,
|
||||
started = SharingStarted.WhileSubscribed(),
|
||||
initialValue = DataState.Loading,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue