mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Fix reconcile summary API results and known room for display
This commit is contained in:
parent
432fd67ce2
commit
a832da2124
3 changed files with 13 additions and 3 deletions
|
@ -122,9 +122,12 @@ class SpaceDirectoryController @Inject constructor(
|
|||
val isSpace = info.roomType == RoomType.SPACE
|
||||
val isJoined = data?.joinedRoomsIds?.contains(info.childRoomId) == true
|
||||
val isLoading = data?.changeMembershipStates?.get(info.childRoomId)?.isInProgress() ?: false
|
||||
// if it's known use that matrixItem because it would have a better computed name
|
||||
val matrixItem = data?.knownRoomSummaries?.find { it.roomId == info.childRoomId }?.toMatrixItem()
|
||||
?: info.toMatrixItem()
|
||||
spaceChildInfoItem {
|
||||
id(info.childRoomId)
|
||||
matrixItem(info.toMatrixItem())
|
||||
matrixItem(matrixItem)
|
||||
avatarRenderer(host.avatarRenderer)
|
||||
topic(info.topic)
|
||||
memberCount(info.activeMemberCount ?: 0)
|
||||
|
|
|
@ -37,7 +37,9 @@ data class SpaceDirectoryState(
|
|||
val joinedRoomsIds: Set<String> = emptySet(),
|
||||
// keys are room alias or roomId
|
||||
val changeMembershipStates: Map<String, ChangeMembershipState> = emptyMap(),
|
||||
val canAddRooms: Boolean = false
|
||||
val canAddRooms: Boolean = false,
|
||||
// cached room summaries of known rooms
|
||||
val knownRoomSummaries : List<RoomSummary> = emptyList()
|
||||
) : MvRxState {
|
||||
constructor(args: SpaceDirectoryArgs) : this(
|
||||
spaceId = args.spaceId
|
||||
|
|
|
@ -102,9 +102,14 @@ class SpaceDirectoryViewModel @AssistedInject constructor(
|
|||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val query = session.spaceService().querySpaceChildren(initialState.spaceId)
|
||||
val knownSummaries = query.second.mapNotNull {
|
||||
session.getRoomSummary(it.childRoomId)
|
||||
?.takeIf { it.membership == Membership.JOIN } // only take if joined because it will be up to date (synced)
|
||||
}
|
||||
setState {
|
||||
copy(
|
||||
spaceSummaryApiResult = Success(query.second)
|
||||
spaceSummaryApiResult = Success(query.second),
|
||||
knownRoomSummaries = knownSummaries
|
||||
)
|
||||
}
|
||||
} catch (failure: Throwable) {
|
||||
|
|
Loading…
Reference in a new issue