Load JoinedRoom in home screen, pass it to the room flow (#5817)
* Load `JoinedRoom` in `HomeFlowNode.navigateToRoom`, then pass it to the next navigation nodes * Add delayed loading indicator for cases when loading the room takes too long * Avoid an extra FFI call in `RustRoomFactory`. Use `RoomInfo.membership` instead. Also use `computation` dispatcher, since it should reduce the delay when switching contexts. * Remove the dispatcher usage when loading the room in `HomeFlowNode`, we immediately call a method that changes the dispatcher used * Make sure only a single room is opened at a time
This commit is contained in:
parent
eedaeb6b35
commit
2e2d68ba83
12 changed files with 180 additions and 53 deletions
|
|
@ -16,6 +16,7 @@ import io.element.android.libraries.matrix.api.core.RoomId
|
|||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
|
|
@ -39,16 +40,21 @@ open class LoadingRoomStateProvider : PreviewParameterProvider<LoadingRoomState>
|
|||
|
||||
@Inject
|
||||
class LoadingRoomStateFlowFactory(private val matrixClient: MatrixClient) {
|
||||
fun create(lifecycleScope: CoroutineScope, roomId: RoomId): StateFlow<LoadingRoomState> =
|
||||
getJoinedRoomFlow(roomId)
|
||||
.map { room ->
|
||||
if (room != null) {
|
||||
LoadingRoomState.Loaded(room)
|
||||
} else {
|
||||
LoadingRoomState.Error
|
||||
fun create(lifecycleScope: CoroutineScope, roomId: RoomId, joinedRoom: JoinedRoom?): StateFlow<LoadingRoomState> {
|
||||
return if (joinedRoom != null) {
|
||||
MutableStateFlow<LoadingRoomState>(LoadingRoomState.Loaded(joinedRoom))
|
||||
} else {
|
||||
getJoinedRoomFlow(roomId)
|
||||
.map { room ->
|
||||
if (room != null) {
|
||||
LoadingRoomState.Loaded(room)
|
||||
} else {
|
||||
LoadingRoomState.Error
|
||||
}
|
||||
}
|
||||
}
|
||||
.stateIn(lifecycleScope, SharingStarted.Eagerly, LoadingRoomState.Loading)
|
||||
.stateIn(lifecycleScope, SharingStarted.Eagerly, LoadingRoomState.Loading)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getJoinedRoomFlow(roomId: RoomId): Flow<JoinedRoom?> = suspend {
|
||||
matrixClient.getJoinedRoom(roomId = roomId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue