From 12b3afbc50507a325ebe3d06e247a16ca9aa5fcf Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 24 May 2022 11:46:43 +0200 Subject: [PATCH] Always use `roomSummaryQueryParams`, and not directly a `RoomSummaryQueryParams.Builder()` Also format and add some Kdoc --- .../session/room/RoomSummaryQueryParams.kt | 25 ++++++++++++------- .../room/list/RoomListSectionBuilderGroup.kt | 6 ++--- .../room/list/RoomListSectionBuilderSpace.kt | 6 ++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt index 5c74dcced1..1e6b648756 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt @@ -24,21 +24,28 @@ import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams +/** + * Create a [RoomSummaryQueryParams] object, calling [init] with a [RoomSummaryQueryParams.Builder] + */ fun roomSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): RoomSummaryQueryParams { - return RoomSummaryQueryParams.Builder().apply(init).build() -} - -fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): SpaceSummaryQueryParams { return RoomSummaryQueryParams.Builder() .apply(init) - .apply { - includeType = listOf(RoomType.SPACE) - excludeType = null - roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS - } .build() } +/** + * Create a [RoomSummaryQueryParams] object, calling [init] with a [RoomSummaryQueryParams.Builder] + * This is specific for spaces, other filters will be applied after invoking [init] + */ +fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): SpaceSummaryQueryParams { + return roomSummaryQueryParams { + init() + includeType = listOf(RoomType.SPACE) + excludeType = null + roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS + } +} + /** * This class can be used to filter room summaries to use with: * [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]. diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index 80c7b4e921..3822067b14 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -38,6 +38,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.model.Membership +import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams class RoomListSectionBuilderGroup( private val coroutineScope: CoroutineScope, @@ -281,9 +282,6 @@ class RoomListSectionBuilderGroup( } private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) { - RoomSummaryQueryParams.Builder() - .apply { builder.invoke(this) } - .build() - .let { block(it) } + block(roomSummaryQueryParams { builder.invoke(this) }) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index c176b1b9a5..edf4ae6e67 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -51,6 +51,7 @@ import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.model.Membership +import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount import timber.log.Timber @@ -429,10 +430,7 @@ class RoomListSectionBuilderSpace( } private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) { - RoomSummaryQueryParams.Builder() - .apply { builder.invoke(this) } - .build() - .let { block(it) } + block(roomSummaryQueryParams { builder.invoke(this) }) } internal fun RoomSummaryQueryParams.process(spaceFilter: RoomListViewModel.SpaceFilterStrategy, currentSpace: String?): RoomSummaryQueryParams {