Fix coroutine scope (#4820)

* Inject the session scope instead of the application scope where it's possible.

* Create AppCoroutineScope annotation to let developers explicitly choose the appropriate CoroutineScope when injecting one.
This commit is contained in:
Benoit Marty
2025-06-04 17:33:51 +02:00
committed by GitHub
parent 88124cd770
commit 03e23477b7
58 changed files with 172 additions and 72 deletions

View File

@@ -36,6 +36,7 @@ import io.element.android.libraries.architecture.BaseFlowNode
import io.element.android.libraries.architecture.createNode
import io.element.android.libraries.designsystem.components.ProgressDialog
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.di.annotations.SessionCoroutineScope
import io.element.android.libraries.matrix.api.encryption.IdentityOidcResetHandle
import io.element.android.libraries.matrix.api.encryption.IdentityPasswordResetHandle
import kotlinx.coroutines.CoroutineScope
@@ -50,7 +51,8 @@ class ResetIdentityFlowNode @AssistedInject constructor(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
private val resetIdentityFlowManager: ResetIdentityFlowManager,
private val coroutineScope: CoroutineScope,
@SessionCoroutineScope
private val sessionCoroutineScope: CoroutineScope,
) : BaseFlowNode<ResetIdentityFlowNode.NavTarget>(
backstack = BackStack(initialElement = NavTarget.Root, savedStateMap = buildContext.savedStateMap),
buildContext = buildContext,
@@ -79,7 +81,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
override fun onStart(owner: LifecycleOwner) {
// If the custom tab / Web browser was opened, we need to cancel the reset job
// when we come back to the node if the reset wasn't successful
coroutineScope.launch {
sessionCoroutineScope.launch {
cancelResetJob()
resetIdentityFlowManager.whenResetIsDone {
@@ -90,7 +92,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
override fun onDestroy(owner: LifecycleOwner) {
// Make sure we cancel the reset job when the node is destroyed, just in case
coroutineScope.launch { cancelResetJob() }
sessionCoroutineScope.launch { cancelResetJob() }
}
})
}
@@ -100,7 +102,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
is NavTarget.Root -> {
val callback = object : ResetIdentityRootNode.Callback {
override fun onContinue() {
coroutineScope.startReset()
sessionCoroutineScope.startReset()
}
}
createNode<ResetIdentityRootNode>(buildContext, listOf(callback))
@@ -157,7 +159,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
if (startResetState.isLoading()) {
ProgressDialog(
properties = DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true),
onDismissRequest = { coroutineScope.launch { cancelResetJob() } }
onDismissRequest = { sessionCoroutineScope.launch { cancelResetJob() } }
)
}