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:
parent
36c7c7ab9b
commit
5f191d9f9c
58 changed files with 172 additions and 72 deletions
|
|
@ -10,6 +10,7 @@ package io.element.android.libraries.voiceplayer.impl
|
|||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.di.annotations.SessionCoroutineScope
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||
import io.element.android.libraries.voiceplayer.api.VoiceMessagePresenterFactory
|
||||
|
|
@ -22,7 +23,8 @@ import kotlin.time.Duration
|
|||
@ContributesBinding(RoomScope::class)
|
||||
class DefaultVoiceMessagePresenterFactory @Inject constructor(
|
||||
private val analyticsService: AnalyticsService,
|
||||
private val scope: CoroutineScope,
|
||||
@SessionCoroutineScope
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val voiceMessagePlayerFactory: VoiceMessagePlayer.Factory,
|
||||
) : VoiceMessagePresenterFactory {
|
||||
override fun createVoiceMessagePresenter(
|
||||
|
|
@ -41,7 +43,7 @@ class DefaultVoiceMessagePresenterFactory @Inject constructor(
|
|||
|
||||
return VoiceMessagePresenter(
|
||||
analyticsService = analyticsService,
|
||||
scope = scope,
|
||||
sessionCoroutineScope = sessionCoroutineScope,
|
||||
player = player,
|
||||
eventId = eventId,
|
||||
duration = duration,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import kotlin.time.Duration.Companion.milliseconds
|
|||
|
||||
class VoiceMessagePresenter(
|
||||
private val analyticsService: AnalyticsService,
|
||||
private val scope: CoroutineScope,
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val player: VoiceMessagePlayer,
|
||||
private val eventId: EventId?,
|
||||
private val duration: Duration,
|
||||
|
|
@ -92,7 +92,7 @@ class VoiceMessagePresenter(
|
|||
} else if (playerState.isReady) {
|
||||
player.play()
|
||||
} else {
|
||||
scope.launch {
|
||||
sessionCoroutineScope.launch {
|
||||
play.runUpdatingState(
|
||||
errorTransform = {
|
||||
analyticsService.trackError(
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ fun TestScope.createVoiceMessagePresenter(
|
|||
mediaSource: MediaSource = MediaSource(contentUri),
|
||||
) = VoiceMessagePresenter(
|
||||
analyticsService = analyticsService,
|
||||
scope = this,
|
||||
sessionCoroutineScope = this,
|
||||
player = DefaultVoiceMessagePlayer(
|
||||
mediaPlayer = mediaPlayer,
|
||||
voiceMessageMediaRepoFactory = { _, _, _ -> voiceMessageMediaRepo },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue