Adds flattenParents field to RoomSummary and corresponding mapping

This commit is contained in:
ericdecanini 2022-05-13 20:43:03 +02:00
parent 21fe5a23fb
commit 50839c206b
2 changed files with 16 additions and 13 deletions

View File

@ -62,6 +62,7 @@ data class RoomSummary(
val roomType: String? = null, val roomType: String? = null,
val spaceParents: List<SpaceParentInfo>? = null, val spaceParents: List<SpaceParentInfo>? = null,
val spaceChildren: List<SpaceChildInfo>? = null, val spaceChildren: List<SpaceChildInfo>? = null,
val flattenParents: List<SpaceParentInfo> = emptyList(),
val flattenParentIds: List<String> = emptyList(), val flattenParentIds: List<String> = emptyList(),
val roomEncryptionAlgorithm: RoomEncryptionAlgorithm? = null val roomEncryptionAlgorithm: RoomEncryptionAlgorithm? = null
) { ) {

View File

@ -194,19 +194,7 @@ internal class RoomSummaryDataSource @Inject constructor(
} }
val dataSourceFactory = realmDataSourceFactory.map { val dataSourceFactory = realmDataSourceFactory.map {
roomSummaryMapper.map(it) roomSummaryMapper.map(it)
}.map { roomSummary -> }.map { it.getWithParents()}
val parents = roomSummary.flattenParentIds.mapNotNull { parentId ->
getRoomSummary(parentId)?.let { parentSummary ->
SpaceParentInfo(
parentId = parentSummary.flattenParentIds.firstOrNull(),
roomSummary = parentSummary,
canonical = true,
viaServers = emptyList()
)
}
}
roomSummary.copy(spaceParents = parents)
}
val boundaries = MutableLiveData(ResultBoundaries()) val boundaries = MutableLiveData(ResultBoundaries())
@ -245,6 +233,20 @@ internal class RoomSummaryDataSource @Inject constructor(
} }
} }
private fun RoomSummary.getWithParents(): RoomSummary {
val parents = flattenParentIds.mapNotNull { parentId ->
getRoomSummary(parentId)?.let { parentSummary ->
SpaceParentInfo(
parentId = parentSummary.flattenParentIds.firstOrNull(),
roomSummary = parentSummary,
canonical = true,
viaServers = emptyList()
)
}
}
return copy(flattenParents = parents)
}
fun getCountLive(queryParams: RoomSummaryQueryParams): LiveData<Int> { fun getCountLive(queryParams: RoomSummaryQueryParams): LiveData<Int> {
val liveRooms = monarchy.findAllManagedWithChanges { val liveRooms = monarchy.findAllManagedWithChanges {
roomSummariesQuery(it, queryParams) roomSummariesQuery(it, queryParams)