Fix reconcile summary API results and known room for display

This commit is contained in:
Valere 2021-05-26 09:24:51 +02:00
parent 432fd67ce2
commit a832da2124
3 changed files with 13 additions and 3 deletions

View File

@ -122,9 +122,12 @@ class SpaceDirectoryController @Inject constructor(
val isSpace = info.roomType == RoomType.SPACE val isSpace = info.roomType == RoomType.SPACE
val isJoined = data?.joinedRoomsIds?.contains(info.childRoomId) == true val isJoined = data?.joinedRoomsIds?.contains(info.childRoomId) == true
val isLoading = data?.changeMembershipStates?.get(info.childRoomId)?.isInProgress() ?: false 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 { spaceChildInfoItem {
id(info.childRoomId) id(info.childRoomId)
matrixItem(info.toMatrixItem()) matrixItem(matrixItem)
avatarRenderer(host.avatarRenderer) avatarRenderer(host.avatarRenderer)
topic(info.topic) topic(info.topic)
memberCount(info.activeMemberCount ?: 0) memberCount(info.activeMemberCount ?: 0)

View File

@ -37,7 +37,9 @@ data class SpaceDirectoryState(
val joinedRoomsIds: Set<String> = emptySet(), val joinedRoomsIds: Set<String> = emptySet(),
// keys are room alias or roomId // keys are room alias or roomId
val changeMembershipStates: Map<String, ChangeMembershipState> = emptyMap(), 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 { ) : MvRxState {
constructor(args: SpaceDirectoryArgs) : this( constructor(args: SpaceDirectoryArgs) : this(
spaceId = args.spaceId spaceId = args.spaceId

View File

@ -102,9 +102,14 @@ class SpaceDirectoryViewModel @AssistedInject constructor(
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
val query = session.spaceService().querySpaceChildren(initialState.spaceId) 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 { setState {
copy( copy(
spaceSummaryApiResult = Success(query.second) spaceSummaryApiResult = Success(query.second),
knownRoomSummaries = knownSummaries
) )
} }
} catch (failure: Throwable) { } catch (failure: Throwable) {