mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Use session scope
This commit is contained in:
parent
c33da38ddb
commit
ecd2d0fb76
3 changed files with 9 additions and 5 deletions
|
@ -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.typing.TypingUsersTracker
|
||||||
import org.matrix.android.sdk.api.session.user.UserService
|
import org.matrix.android.sdk.api.session.user.UserService
|
||||||
import org.matrix.android.sdk.api.session.widgets.WidgetService
|
import org.matrix.android.sdk.api.session.widgets.WidgetService
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface defines interactions with a session.
|
* This interface defines interactions with a session.
|
||||||
|
@ -276,5 +278,6 @@ interface Session :
|
||||||
/**
|
/**
|
||||||
* Launch a coroutine using the session scope
|
* Launch a coroutine using the session scope
|
||||||
*/
|
*/
|
||||||
fun launch(block: suspend () -> Unit )
|
fun launch(context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
block: suspend () -> Unit )
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ import org.matrix.android.sdk.internal.util.createUIHandler
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
@SessionScope
|
@SessionScope
|
||||||
internal class DefaultSession @Inject constructor(
|
internal class DefaultSession @Inject constructor(
|
||||||
|
@ -312,8 +313,9 @@ internal class DefaultSession @Inject constructor(
|
||||||
RealmDebugTools(realmConfiguration).logInfo("Session")
|
RealmDebugTools(realmConfiguration).logInfo("Session")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun launch(block: suspend () -> Unit) {
|
override fun launch(context: CoroutineContext,
|
||||||
sessionScope?.launch {
|
block: suspend () -> Unit) {
|
||||||
|
sessionScope?.launch(context) {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ import io.reactivex.Observable
|
||||||
import io.reactivex.rxkotlin.subscribeBy
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.NonCancellable
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.commonmark.parser.Parser
|
import org.commonmark.parser.Parser
|
||||||
|
@ -571,7 +570,7 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
* Convert a send mode to a draft and save the draft
|
* Convert a send mode to a draft and save the draft
|
||||||
*/
|
*/
|
||||||
private fun handleSaveDraft(action: RoomDetailAction.SaveDraft) = withState {
|
private fun handleSaveDraft(action: RoomDetailAction.SaveDraft) = withState {
|
||||||
viewModelScope.launch(NonCancellable) {
|
session.launch {
|
||||||
when {
|
when {
|
||||||
it.sendMode is SendMode.REGULAR && !it.sendMode.fromSharing -> {
|
it.sendMode is SendMode.REGULAR && !it.sendMode.fromSharing -> {
|
||||||
setState { copy(sendMode = it.sendMode.copy(action.draft)) }
|
setState { copy(sendMode = it.sendMode.copy(action.draft)) }
|
||||||
|
|
Loading…
Reference in a new issue