Skip to content

Commit

Permalink
Fix reset identity with password stuck in loading state. (element-hq#…
Browse files Browse the repository at this point in the history
…3317)

Make sure `resetIdentityFlowManager.whenResetIsDone` is registered *after* the previous reset attempt is cancelled, otherwise the current one will be cancelled instead.
  • Loading branch information
jmartinesp authored Aug 20, 2024
1 parent 534e3a8 commit 0686745
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ class ResetIdentityFlowNode @AssistedInject constructor(
override fun onBuilt() {
super.onBuilt()

resetIdentityFlowManager.whenResetIsDone {
plugins<Callback>().forEach { it.onDone() }
}

lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onStart(owner: LifecycleOwner) {
// If the custom tab was opened, we need to cancel the reset job
// when we come back to the node if the reset wasn't successful
cancelResetJob()
coroutineScope.launch {
cancelResetJob()

resetIdentityFlowManager.whenResetIsDone {
plugins<Callback>().forEach { it.onDone() }
}
}
}

override fun onDestroy(owner: LifecycleOwner) {
// Make sure we cancel the reset job when the node is destroyed, just in case
cancelResetJob()
coroutineScope.launch { cancelResetJob() }
}
})
}
Expand Down Expand Up @@ -154,10 +156,10 @@ class ResetIdentityFlowNode @AssistedInject constructor(
}
}

private fun cancelResetJob() {
private suspend fun cancelResetJob() {
resetJob?.cancel()
resetJob = null
coroutineScope.launch { resetIdentityFlowManager.cancel() }
resetIdentityFlowManager.cancel()
}

@Composable
Expand All @@ -171,7 +173,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
if (startResetState.isLoading()) {
ProgressDialog(
properties = DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true),
onDismissRequest = { cancelResetJob() }
onDismissRequest = { coroutineScope.launch { cancelResetJob() } }
)
}

Expand Down

0 comments on commit 0686745

Please sign in to comment.