Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bca/space explore pagination #3926

Merged
merged 7 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3693.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Space summary pagination
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.model.GuestAccess
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
import org.matrix.android.sdk.api.session.room.model.RoomGuestAccessContent
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
Expand All @@ -42,7 +39,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomType
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.api.session.space.JoinSpaceResult
import org.matrix.android.sdk.common.CommonTestHelper
import org.matrix.android.sdk.common.SessionTestParams
Expand Down Expand Up @@ -162,7 +158,7 @@ class SpaceCreationTest : InstrumentedTest {

commonTestHelper.waitWithLatch {
GlobalScope.launch {
syncedSpace?.addChildren(firstChild!!, listOf(aliceSession.sessionParams.homeServerHost ?: ""), "a", true, suggested = true)
syncedSpace?.addChildren(firstChild!!, listOf(aliceSession.sessionParams.homeServerHost ?: ""), "a", suggested = true)
it.countDown()
}
}
Expand All @@ -181,7 +177,7 @@ class SpaceCreationTest : InstrumentedTest {

commonTestHelper.waitWithLatch {
GlobalScope.launch {
syncedSpace?.addChildren(secondChild!!, listOf(aliceSession.sessionParams.homeServerHost ?: ""), "b", false, suggested = true)
syncedSpace?.addChildren(secondChild!!, listOf(aliceSession.sessionParams.homeServerHost ?: ""), "b", suggested = true)
it.countDown()
}
}
Expand All @@ -202,19 +198,20 @@ class SpaceCreationTest : InstrumentedTest {
assertEquals("Room name should be set", roomName, spaceBobPov?.asRoom()?.roomSummary()?.name)
assertEquals("Room topic should be set", topic, spaceBobPov?.asRoom()?.roomSummary()?.topic)

// /!\ AUTO_JOIN has been descoped
// check if bob has joined automatically the first room

val bobMembershipFirstRoom = bobSession.getRoomSummary(firstChild!!)?.membership
assertEquals("Bob should have joined this room", Membership.JOIN, bobMembershipFirstRoom)
RoomSummaryQueryParams.Builder()

val childCount = bobSession.getRoomSummaries(
roomSummaryQueryParams {
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(spaceId)
}
).size

assertEquals("Unexpected number of joined children", 1, childCount)
// val bobMembershipFirstRoom = bobSession.getRoomSummary(firstChild!!)?.membership
// assertEquals("Bob should have joined this room", Membership.JOIN, bobMembershipFirstRoom)
// RoomSummaryQueryParams.Builder()
//
// val childCount = bobSession.getRoomSummaries(
// roomSummaryQueryParams {
// activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(spaceId)
// }
// ).size
//
// assertEquals("Unexpected number of joined children", 1, childCount)

commonTestHelper.signOutAndClose(aliceSession)
commonTestHelper.signOutAndClose(bobSession)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class SpaceChildInfo(
val avatarUrl: String?,
val order: String?,
val activeMemberCount: Int?,
val autoJoin: Boolean,
// val autoJoin: Boolean,
val viaServers: List<String>,
val parentRoomId: String?,
val suggested: Boolean?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface Space {
suspend fun addChildren(roomId: String,
viaServers: List<String>?,
order: String?,
autoJoin: Boolean = false,
// autoJoin: Boolean = false,
suggested: Boolean? = false)

fun getChildInfo(roomId: String): SpaceChildContent?
Expand All @@ -46,8 +46,8 @@ interface Space {
@Throws
suspend fun setChildrenOrder(roomId: String, order: String?)

@Throws
suspend fun setChildrenAutoJoin(roomId: String, autoJoin: Boolean)
// @Throws
// suspend fun setChildrenAutoJoin(roomId: String, autoJoin: Boolean)

@Throws
suspend fun setChildrenSuggested(roomId: String, suggested: Boolean)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.android.sdk.api.session.space

import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo

data class SpaceHierarchyData(
val rootSummary: RoomSummary,
val children: List<SpaceChildInfo>,
val childrenState: List<Event>,
val nextToken: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package org.matrix.android.sdk.api.session.space

import android.net.Uri
import androidx.lifecycle.LiveData
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
import org.matrix.android.sdk.internal.session.space.peeking.SpacePeekResult

typealias SpaceSummaryQueryParams = RoomSummaryQueryParams
Expand Down Expand Up @@ -58,10 +58,17 @@ interface SpaceService {

/**
* Get's information of a space by querying the server
* @param suggestedOnly If true, return only child events and rooms where the m.space.child event has suggested: true.
* @param limit a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer.
* @param from: Optional. Pagination token given to retrieve the next set of rooms. Note that if a pagination token is provided,
* then the parameters given for suggested_only and max_depth must be the same.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_depth is not a part of this API, the SDK forces the value to 1.
So either expose max_depth to the client applications here, or update this comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed comment

*/
suspend fun querySpaceChildren(spaceId: String,
suggestedOnly: Boolean? = null,
autoJoinedOnly: Boolean? = null): Pair<RoomSummary, List<SpaceChildInfo>>
limit: Int? = null,
from: String? = null,
// when paginating, pass back the m.space.child state events
knownStateList: List<Event>? = null): SpaceHierarchyData

/**
* Get a live list of space summaries. This list is refreshed as soon as the data changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ data class SpaceChildContent(
* or consist of more than 50 characters, are forbidden and should be ignored if received.)
*/
@Json(name = "order") val order: String? = null,
/**
* The auto_join flag on a child listing allows a space admin to list the sub-spaces and rooms in that space which should
* be automatically joined by members of that space.
* (This is not a force-join, which are descoped for a future MSC; the user can subsequently part these room if they desire.)
*/
@Json(name = "auto_join") val autoJoin: Boolean? = false,
// /**
// * The auto_join flag on a child listing allows a space admin to list the sub-spaces and rooms in that space which should
// * be automatically joined by members of that space.
// * (This is not a force-join, which are descoped for a future MSC; the user can subsequently part these room if they desire.)
// */
// @Json(name = "auto_join") val autoJoin: Boolean? = false,

/**
* If `suggested` is set to `true`, that indicates that the child should be advertised to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa
avatarUrl = it.childSummaryEntity?.avatarUrl,
activeMemberCount = it.childSummaryEntity?.joinedMembersCount,
order = it.order,
autoJoin = it.autoJoin ?: false,
// autoJoin = it.autoJoin ?: false,
viaServers = it.viaServers.toList(),
parentRoomId = roomSummaryEntity.roomId,
suggested = it.suggested,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class RoomChildRelationInfo(
data class SpaceChildInfo(
val roomId: String,
val order: String?,
val autoJoin: Boolean,
// val autoJoin: Boolean,
val viaServers: List<String>
)

Expand Down Expand Up @@ -71,7 +71,7 @@ internal class RoomChildRelationInfo(
SpaceChildInfo(
roomId = it.stateKey,
order = scc.validOrder(),
autoJoin = scc.autoJoin ?: false,
// autoJoin = scc.autoJoin ?: false,
viaServers = via
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ internal class RoomSummaryUpdater @Inject constructor(
this.childRoomId = child.roomId
this.childSummaryEntity = RoomSummaryEntity.where(realm, child.roomId).findFirst()
this.order = child.order
this.autoJoin = child.autoJoin
// this.autoJoin = child.autoJoin
this.viaServers.addAll(child.viaServers)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class DefaultSpace(
override suspend fun addChildren(roomId: String,
viaServers: List<String>?,
order: String?,
autoJoin: Boolean,
// autoJoin: Boolean,
suggested: Boolean?) {
// Find best via
val bestVia = viaServers
Expand All @@ -69,7 +69,6 @@ internal class DefaultSpace(
stateKey = roomId,
body = SpaceChildContent(
via = bestVia,
autoJoin = autoJoin,
order = order,
suggested = suggested
).toContent()
Expand All @@ -90,7 +89,7 @@ internal class DefaultSpace(
body = SpaceChildContent(
order = null,
via = null,
autoJoin = null,
// autoJoin = null,
suggested = null
).toContent()
)
Expand All @@ -115,35 +114,35 @@ internal class DefaultSpace(
body = SpaceChildContent(
order = order,
via = existing.via,
autoJoin = existing.autoJoin,
// autoJoin = existing.autoJoin,
suggested = existing.suggested
).toContent()
)
}

override suspend fun setChildrenAutoJoin(roomId: String, autoJoin: Boolean) {
val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
.firstOrNull()
?.content.toModel<SpaceChildContent>()
?: throw IllegalArgumentException("$roomId is not a child of this space")

if (existing.autoJoin == autoJoin) {
// nothing to do?
return
}

// edit state event and set via to null
room.sendStateEvent(
eventType = EventType.STATE_SPACE_CHILD,
stateKey = roomId,
body = SpaceChildContent(
order = existing.order,
via = existing.via,
autoJoin = autoJoin,
suggested = existing.suggested
).toContent()
)
}
// override suspend fun setChildrenAutoJoin(roomId: String, autoJoin: Boolean) {
// val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
// .firstOrNull()
// ?.content.toModel<SpaceChildContent>()
// ?: throw IllegalArgumentException("$roomId is not a child of this space")
//
// if (existing.autoJoin == autoJoin) {
// // nothing to do?
// return
// }
//
// // edit state event and set via to null
// room.sendStateEvent(
// eventType = EventType.STATE_SPACE_CHILD,
// stateKey = roomId,
// body = SpaceChildContent(
// order = existing.order,
// via = existing.via,
// autoJoin = autoJoin,
// suggested = existing.suggested
// ).toContent()
// )
// }

override suspend fun setChildrenSuggested(roomId: String, suggested: Boolean) {
val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
Expand All @@ -162,7 +161,7 @@ internal class DefaultSpace(
body = SpaceChildContent(
order = existing.order,
via = existing.via,
autoJoin = existing.autoJoin,
// autoJoin = existing.autoJoin,
suggested = suggested
).toContent()
)
Expand Down
Loading