Session.getRoom : suspend the whole method
This commit is contained in:
parent
a87ae86398
commit
c0b8388fad
1 changed files with 18 additions and 15 deletions
|
|
@ -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,24 +158,27 @@ class RustMatrixClient constructor(
|
||||||
roomSummaryDataSource.awaitAllRoomsAreLoaded()
|
roomSummaryDataSource.awaitAllRoomsAreLoaded()
|
||||||
cachedPairOfRoom = pairOfRoom(roomId)
|
cachedPairOfRoom = pairOfRoom(roomId)
|
||||||
}
|
}
|
||||||
if (cachedPairOfRoom == null) return null
|
return@withContext if (cachedPairOfRoom == null) {
|
||||||
val (roomListItem, fullRoom) = cachedPairOfRoom
|
null
|
||||||
return RustMatrixRoom(
|
} else {
|
||||||
sessionId = sessionId,
|
val (roomListItem, fullRoom) = cachedPairOfRoom
|
||||||
roomListItem = roomListItem,
|
RustMatrixRoom(
|
||||||
innerRoom = fullRoom,
|
sessionId = sessionId,
|
||||||
sessionCoroutineScope = sessionCoroutineScope,
|
roomListItem = roomListItem,
|
||||||
coroutineDispatchers = dispatchers,
|
innerRoom = fullRoom,
|
||||||
systemClock = clock,
|
sessionCoroutineScope = sessionCoroutineScope,
|
||||||
roomContentForwarder = roomContentForwarder,
|
coroutineDispatchers = dispatchers,
|
||||||
sessionData = sessionStore.getSession(sessionId.value)!!,
|
systemClock = clock,
|
||||||
)
|
roomContentForwarder = roomContentForwarder,
|
||||||
|
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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue