Use session scope

This commit is contained in:
Benoit Marty 2021-04-19 16:01:33 +02:00 committed by Benoit Marty
parent c33da38ddb
commit ecd2d0fb76
3 changed files with 9 additions and 5 deletions

View File

@ -56,6 +56,8 @@ import org.matrix.android.sdk.api.session.thirdparty.ThirdPartyService
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
import org.matrix.android.sdk.api.session.user.UserService
import org.matrix.android.sdk.api.session.widgets.WidgetService
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
/**
* This interface defines interactions with a session.
@ -276,5 +278,6 @@ interface Session :
/**
* Launch a coroutine using the session scope
*/
fun launch(block: suspend () -> Unit )
fun launch(context: CoroutineContext = EmptyCoroutineContext,
block: suspend () -> Unit )
}

View File

@ -79,6 +79,7 @@ import org.matrix.android.sdk.internal.util.createUIHandler
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Provider
import kotlin.coroutines.CoroutineContext
@SessionScope
internal class DefaultSession @Inject constructor(
@ -312,8 +313,9 @@ internal class DefaultSession @Inject constructor(
RealmDebugTools(realmConfiguration).logInfo("Session")
}
override fun launch(block: suspend () -> Unit) {
sessionScope?.launch {
override fun launch(context: CoroutineContext,
block: suspend () -> Unit) {
sessionScope?.launch(context) {
block()
}
}

View File

@ -59,7 +59,6 @@ import io.reactivex.Observable
import io.reactivex.rxkotlin.subscribeBy
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.commonmark.parser.Parser
@ -571,7 +570,7 @@ class RoomDetailViewModel @AssistedInject constructor(
* Convert a send mode to a draft and save the draft
*/
private fun handleSaveDraft(action: RoomDetailAction.SaveDraft) = withState {
viewModelScope.launch(NonCancellable) {
session.launch {
when {
it.sendMode is SendMode.REGULAR && !it.sendMode.fromSharing -> {
setState { copy(sendMode = it.sendMode.copy(action.draft)) }