Room: dispatch getRooms on background thread

This commit is contained in:
ganfra 2023-07-05 12:56:39 +02:00
parent 8667784271
commit 434de4132e

View file

@ -55,6 +55,7 @@ import io.element.android.services.toolbox.api.systemclock.SystemClock
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.firstOrNull
@ -150,12 +151,10 @@ class RustMatrixClient constructor(
) )
} }
private suspend fun pairOfRoom(roomId: RoomId): Pair<RoomListItem, Room>? { private suspend fun pairOfRoom(roomId: RoomId): Pair<RoomListItem, Room>? = withContext(dispatchers.io) {
Timber.v("Resume get pair of room for $roomId")
val cachedRoomListItem = roomListService.roomOrNull(roomId.value) val cachedRoomListItem = roomListService.roomOrNull(roomId.value)
val fullRoom = cachedRoomListItem?.fullRoom() val fullRoom = cachedRoomListItem?.fullRoom()
Timber.v("Finish get pair of room for $roomId") if (cachedRoomListItem == null || fullRoom == null) {
return if (cachedRoomListItem == null || fullRoom == null) {
null null
} else { } else {
Pair(cachedRoomListItem, fullRoom) Pair(cachedRoomListItem, fullRoom)