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

@@ -18,6 +18,7 @@ import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.architecture.runCatchingUpdatingState
import io.element.android.libraries.core.bool.orFalse
import io.element.android.libraries.di.annotations.SessionCoroutineScope
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.JoinedRoom
@@ -31,7 +32,8 @@ import kotlin.coroutines.cancellation.CancellationException
class SharePresenter @AssistedInject constructor(
@Assisted private val intent: Intent,
private val appCoroutineScope: CoroutineScope,
@SessionCoroutineScope
private val sessionCoroutineScope: CoroutineScope,
private val shareIntentHandler: ShareIntentHandler,
private val matrixClient: MatrixClient,
private val mediaPreProcessor: MediaPreProcessor,
@@ -46,7 +48,7 @@ class SharePresenter @AssistedInject constructor(
private val shareActionState: MutableState<AsyncAction<List<RoomId>>> = mutableStateOf(AsyncAction.Uninitialized)
fun onRoomSelected(roomIds: List<RoomId>) {
appCoroutineScope.share(intent, roomIds)
sessionCoroutineScope.share(intent, roomIds)
}
@Composable

View File

@@ -169,7 +169,7 @@ class SharePresenterTest {
): SharePresenter {
return SharePresenter(
intent = intent,
appCoroutineScope = this,
sessionCoroutineScope = this,
shareIntentHandler = shareIntentHandler,
matrixClient = matrixClient,
mediaPreProcessor = mediaPreProcessor,