Better handling on null reset handler.
This is not an error, but in this case, the reset identity is successful.
This commit is contained in:
parent
8e7d8175d7
commit
dfaa350167
6 changed files with 28 additions and 20 deletions
|
|
@ -36,8 +36,8 @@ class ResetIdentityFlowManager @Inject constructor(
|
|||
@SessionCoroutineScope private val sessionCoroutineScope: CoroutineScope,
|
||||
private val sessionVerificationService: SessionVerificationService,
|
||||
) {
|
||||
private val resetHandleFlow: MutableStateFlow<AsyncData<IdentityResetHandle>> = MutableStateFlow(AsyncData.Uninitialized)
|
||||
val currentHandleFlow: StateFlow<AsyncData<IdentityResetHandle>> = resetHandleFlow
|
||||
private val resetHandleFlow: MutableStateFlow<AsyncData<IdentityResetHandle?>> = MutableStateFlow(AsyncData.Uninitialized)
|
||||
val currentHandleFlow: StateFlow<AsyncData<IdentityResetHandle?>> = resetHandleFlow
|
||||
private var whenResetIsDoneWaitingJob: Job? = null
|
||||
|
||||
fun whenResetIsDone(block: () -> Unit) {
|
||||
|
|
@ -47,7 +47,7 @@ class ResetIdentityFlowManager @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun getResetHandle(): StateFlow<AsyncData<IdentityResetHandle>> {
|
||||
fun getResetHandle(): StateFlow<AsyncData<IdentityResetHandle?>> {
|
||||
return if (resetHandleFlow.value.isLoading() || resetHandleFlow.value.isSuccess()) {
|
||||
resetHandleFlow
|
||||
} else {
|
||||
|
|
@ -56,13 +56,11 @@ class ResetIdentityFlowManager @Inject constructor(
|
|||
sessionCoroutineScope.launch {
|
||||
matrixClient.encryptionService().startIdentityReset()
|
||||
.onSuccess { handle ->
|
||||
resetHandleFlow.value = if (handle != null) {
|
||||
AsyncData.Success(handle)
|
||||
} else {
|
||||
AsyncData.Failure(IllegalStateException("Could not get a reset identity handle"))
|
||||
}
|
||||
resetHandleFlow.value = AsyncData.Success(handle)
|
||||
}
|
||||
.onFailure {
|
||||
resetHandleFlow.value = AsyncData.Failure(it)
|
||||
}
|
||||
.onFailure { resetHandleFlow.value = AsyncData.Failure(it) }
|
||||
}
|
||||
|
||||
resetHandleFlow
|
||||
|
|
|
|||
|
|
@ -140,6 +140,9 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
|||
}
|
||||
is AsyncData.Success -> {
|
||||
when (val handle = state.data) {
|
||||
null -> {
|
||||
Timber.d("No reset handle return, the reset is done.")
|
||||
}
|
||||
is IdentityOidcResetHandle -> {
|
||||
if (oidcEntryPoint.canUseCustomTab()) {
|
||||
activity.openUrlInChromeCustomTab(null, false, handle.url)
|
||||
|
|
|
|||
|
|
@ -73,7 +73,9 @@ class ResetIdentityFlowManagerTest {
|
|||
|
||||
flowManager.getResetHandle().test {
|
||||
assertThat(awaitItem().isLoading()).isTrue()
|
||||
assertThat(awaitItem().isFailure()).isTrue()
|
||||
val finalItem = awaitItem()
|
||||
assertThat(finalItem.isSuccess()).isTrue()
|
||||
assertThat(finalItem.dataOrNull()).isNull()
|
||||
startResetLambda.assertions().isCalledOnce()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue