Replaces children state event room id with space id

This commit is contained in:
ericdecanini 2022-03-09 18:42:35 +01:00
parent f76f73f8ad
commit 2f706d6fae
1 changed files with 7 additions and 6 deletions

View File

@ -172,30 +172,31 @@ internal class DefaultSpaceService @Inject constructor(
spaceRootResponse: SpaceChildSummaryResponse?, spaceRootResponse: SpaceChildSummaryResponse?,
knownStateList: List<Event>?, knownStateList: List<Event>?,
) = this?.filterIdIsNot(spaceId) ) = this?.filterIdIsNot(spaceId)
?.toSpaceChildInfoList(spaceRootResponse, knownStateList) ?.toSpaceChildInfoList(spaceId, spaceRootResponse, knownStateList)
.orEmpty() .orEmpty()
private fun List<SpaceChildSummaryResponse>.filterIdIsNot(spaceId: String) = filter { it.roomId != spaceId } private fun List<SpaceChildSummaryResponse>.filterIdIsNot(spaceId: String) = filter { it.roomId != spaceId }
private fun List<SpaceChildSummaryResponse>.toSpaceChildInfoList( private fun List<SpaceChildSummaryResponse>.toSpaceChildInfoList(
spaceId: String,
rootRoomResponse: SpaceChildSummaryResponse?, rootRoomResponse: SpaceChildSummaryResponse?,
knownStateList: List<Event>?, knownStateList: List<Event>?,
) = flatMap { spaceChildSummary -> ) = flatMap { spaceChildSummary ->
(rootRoomResponse?.childrenState ?: knownStateList) (rootRoomResponse?.childrenState ?: knownStateList)
?.filter { it.isChildOf(spaceChildSummary) } ?.filter { it.isChildOf(spaceChildSummary) }
?.mapNotNull { childStateEvent -> childStateEvent.toSpaceChildInfo(spaceChildSummary) } ?.mapNotNull { childStateEvent -> childStateEvent.toSpaceChildInfo(spaceId, spaceChildSummary) }
.orEmpty() .orEmpty()
} }
private fun Event.isChildOf(space: SpaceChildSummaryResponse) = stateKey == space.roomId && type == EventType.STATE_SPACE_CHILD private fun Event.isChildOf(space: SpaceChildSummaryResponse) = stateKey == space.roomId && type == EventType.STATE_SPACE_CHILD
private fun Event.toSpaceChildInfo(summary: SpaceChildSummaryResponse) = content.toModel<SpaceChildContent>()?.let { content -> private fun Event.toSpaceChildInfo(spaceId: String, summary: SpaceChildSummaryResponse) = content.toModel<SpaceChildContent>()?.let { content ->
createSpaceChildInfo(summary, this, content) createSpaceChildInfo(spaceId, summary, content)
} }
private fun createSpaceChildInfo( private fun createSpaceChildInfo(
spaceId: String,
summary: SpaceChildSummaryResponse, summary: SpaceChildSummaryResponse,
stateEvent: Event,
content: SpaceChildContent content: SpaceChildContent
) = SpaceChildInfo( ) = SpaceChildInfo(
childRoomId = summary.roomId, childRoomId = summary.roomId,
@ -207,7 +208,7 @@ internal class DefaultSpaceService @Inject constructor(
order = content.order, order = content.order,
viaServers = content.via.orEmpty(), viaServers = content.via.orEmpty(),
activeMemberCount = summary.numJoinedMembers, activeMemberCount = summary.numJoinedMembers,
parentRoomId = stateEvent.roomId, parentRoomId = spaceId,
suggested = content.suggested, suggested = content.suggested,
canonicalAlias = summary.canonicalAlias, canonicalAlias = summary.canonicalAlias,
aliases = summary.aliases, aliases = summary.aliases,