From 50839c206bf14e2783c8953275580f547a990ba2 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 13 May 2022 20:43:03 +0200 Subject: [PATCH] Adds flattenParents field to RoomSummary and corresponding mapping --- .../sdk/api/session/room/model/RoomSummary.kt | 1 + .../room/summary/RoomSummaryDataSource.kt | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index 71c1d8303e..5a265c2b26 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -62,6 +62,7 @@ data class RoomSummary( val roomType: String? = null, val spaceParents: List? = null, val spaceChildren: List? = null, + val flattenParents: List = emptyList(), val flattenParentIds: List = emptyList(), val roomEncryptionAlgorithm: RoomEncryptionAlgorithm? = null ) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index b165fb3001..752c828710 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -194,19 +194,7 @@ internal class RoomSummaryDataSource @Inject constructor( } val dataSourceFactory = realmDataSourceFactory.map { roomSummaryMapper.map(it) - }.map { roomSummary -> - 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) - } + }.map { it.getWithParents()} 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 { val liveRooms = monarchy.findAllManagedWithChanges { roomSummariesQuery(it, queryParams)