Remove explicit coroutine context changes

Signed-off-by: aqulu <dev@aqu.lu>
This commit is contained in:
aqulu 2020-12-08 22:11:35 +09:00
parent 19d421df84
commit 40b9f03132

View file

@ -20,7 +20,6 @@ import android.net.Uri
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject import com.squareup.inject.assisted.AssistedInject
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
@ -36,12 +35,10 @@ import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.session.content.FileUploader import org.matrix.android.sdk.internal.session.content.FileUploader
import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasTask import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasTask
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String, internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
private val stateEventDataSource: StateEventDataSource, private val stateEventDataSource: StateEventDataSource,
private val sendStateTask: SendStateTask, private val sendStateTask: SendStateTask,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val fileUploader: FileUploader, private val fileUploader: FileUploader,
private val addRoomAliasTask: AddRoomAliasTask private val addRoomAliasTask: AddRoomAliasTask
) : StateService { ) : StateService {
@ -123,33 +120,29 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
} }
override suspend fun updateJoinRule(joinRules: RoomJoinRules?, guestAccess: GuestAccess?) { override suspend fun updateJoinRule(joinRules: RoomJoinRules?, guestAccess: GuestAccess?) {
withContext(coroutineDispatchers.main) { if (joinRules != null) {
if (joinRules != null) { sendStateEvent(
sendStateEvent( eventType = EventType.STATE_ROOM_JOIN_RULES,
eventType = EventType.STATE_ROOM_JOIN_RULES, body = RoomJoinRulesContent(joinRules).toContent(),
body = RoomJoinRulesContent(joinRules).toContent(), stateKey = null
stateKey = null )
) }
} if (guestAccess != null) {
if (guestAccess != null) { sendStateEvent(
sendStateEvent( eventType = EventType.STATE_ROOM_GUEST_ACCESS,
eventType = EventType.STATE_ROOM_GUEST_ACCESS, body = RoomGuestAccessContent(guestAccess).toContent(),
body = RoomGuestAccessContent(guestAccess).toContent(), stateKey = null
stateKey = null )
)
}
} }
} }
override suspend fun updateAvatar(avatarUri: Uri, fileName: String) { override suspend fun updateAvatar(avatarUri: Uri, fileName: String) {
withContext(coroutineDispatchers.main) { val response = fileUploader.uploadFromUri(avatarUri, fileName, "image/jpeg")
val response = fileUploader.uploadFromUri(avatarUri, fileName, "image/jpeg") sendStateEvent(
sendStateEvent( eventType = EventType.STATE_ROOM_AVATAR,
eventType = EventType.STATE_ROOM_AVATAR, body = mapOf("url" to response.contentUri),
body = mapOf("url" to response.contentUri), stateKey = null
stateKey = null )
)
}
} }
override suspend fun deleteAvatar() { override suspend fun deleteAvatar() {