From fd4de40851cb7e0c62f6060f374b943db3159639 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Tue, 20 Aug 2024 21:04:20 +0200 Subject: [PATCH] Fix reset identity with password stuck in loading state. (#3317) Make sure `resetIdentityFlowManager.whenResetIsDone` is registered *after* the previous reset attempt is cancelled, otherwise the current one will be cancelled instead. --- .../impl/reset/ResetIdentityFlowNode.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/reset/ResetIdentityFlowNode.kt b/features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/reset/ResetIdentityFlowNode.kt index 50dcc2dd12..9bd8aeff03 100644 --- a/features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/reset/ResetIdentityFlowNode.kt +++ b/features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/reset/ResetIdentityFlowNode.kt @@ -87,20 +87,22 @@ class ResetIdentityFlowNode @AssistedInject constructor( override fun onBuilt() { super.onBuilt() - resetIdentityFlowManager.whenResetIsDone { - plugins().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().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() } } }) } @@ -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 @@ -171,7 +173,7 @@ class ResetIdentityFlowNode @AssistedInject constructor( if (startResetState.isLoading()) { ProgressDialog( properties = DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true), - onDismissRequest = { cancelResetJob() } + onDismissRequest = { coroutineScope.launch { cancelResetJob() } } ) }