Session.getRoom : suspend the whole method

This commit is contained in:
ganfra 2023-07-21 14:12:54 +02:00
parent a87ae86398
commit c0b8388fad

View file

@ -150,7 +150,7 @@ class RustMatrixClient constructor(
}.launchIn(sessionCoroutineScope) }.launchIn(sessionCoroutineScope)
} }
override suspend fun getRoom(roomId: RoomId): MatrixRoom? { override suspend fun getRoom(roomId: RoomId): MatrixRoom? = withContext(sessionDispatcher) {
// Check if already in memory... // Check if already in memory...
var cachedPairOfRoom = pairOfRoom(roomId) var cachedPairOfRoom = pairOfRoom(roomId)
if (cachedPairOfRoom == null) { if (cachedPairOfRoom == null) {
@ -158,9 +158,11 @@ class RustMatrixClient constructor(
roomSummaryDataSource.awaitAllRoomsAreLoaded() roomSummaryDataSource.awaitAllRoomsAreLoaded()
cachedPairOfRoom = pairOfRoom(roomId) cachedPairOfRoom = pairOfRoom(roomId)
} }
if (cachedPairOfRoom == null) return null return@withContext if (cachedPairOfRoom == null) {
null
} else {
val (roomListItem, fullRoom) = cachedPairOfRoom val (roomListItem, fullRoom) = cachedPairOfRoom
return RustMatrixRoom( RustMatrixRoom(
sessionId = sessionId, sessionId = sessionId,
roomListItem = roomListItem, roomListItem = roomListItem,
innerRoom = fullRoom, innerRoom = fullRoom,
@ -171,11 +173,12 @@ class RustMatrixClient constructor(
sessionData = sessionStore.getSession(sessionId.value)!!, sessionData = sessionStore.getSession(sessionId.value)!!,
) )
} }
}
private suspend fun pairOfRoom(roomId: RoomId): Pair<RoomListItem, Room>? = withContext(sessionDispatcher) { private fun pairOfRoom(roomId: RoomId): Pair<RoomListItem, Room>? {
val cachedRoomListItem = roomListService.roomOrNull(roomId.value) val cachedRoomListItem = roomListService.roomOrNull(roomId.value)
val fullRoom = cachedRoomListItem?.fullRoom() val fullRoom = cachedRoomListItem?.fullRoom()
if (cachedRoomListItem == null || fullRoom == null) { return if (cachedRoomListItem == null || fullRoom == null) {
Timber.d("No room cached for $roomId") Timber.d("No room cached for $roomId")
null null
} else { } else {