From 8cd3750cde65c8bbfc97cb578d00111b6bf62ee8 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Fri, 11 Sep 2026 17:36:38 +0200 Subject: [PATCH] Make global search use a `Joined` filter for room results (#7695) Before this, global search returned also invites, which wasn't planned. --- .../features/home/impl/search/GlobalSearchPresenter.kt | 10 +++++++++- .../home/impl/search/RoomListSearchDataSource.kt | 8 ++++++-- .../home/impl/search/RoomListSearchPresenter.kt | 2 +- .../home/impl/search/GlobalSearchPresenterTest.kt | 6 ++++++ .../libraries/matrix/api/roomlist/RoomListFilter.kt | 5 +++++ .../matrix/impl/roomlist/RoomListFilterMapper.kt | 2 ++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt index 6e153344c9..fe7c4aba3e 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt @@ -31,6 +31,7 @@ import io.element.android.libraries.matrix.api.MatrixClient import io.element.android.libraries.matrix.api.permalink.PermalinkParser import io.element.android.libraries.matrix.api.room.RoomInfo import io.element.android.libraries.matrix.api.roomlist.LatestEventValue +import io.element.android.libraries.matrix.api.roomlist.RoomListFilter import io.element.android.libraries.matrix.api.search.MessageSearch import io.element.android.libraries.matrix.api.search.MessageSearchPaginationState import io.element.android.libraries.matrix.api.search.MessageSearchResult @@ -94,7 +95,14 @@ class GlobalSearchPresenter( AsyncData.Uninitialized } - launch { roomListSearchDataSource.setSearchQuery(queryState.text.toString()) } + // Apply the query to the room list search, looking only for joined rooms matching the query + launch { + roomListSearchDataSource.setSearchQuery( + searchQuery = queryState.text.toString(), + additionalFilters = RoomListFilter.Joined, + ) + } + // Apply the query to the message search too launch { currentMessageSearch.setQuery(queryState.text.toString()) .onFailure { Timber.e(it, "Could not set query for message search") } diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchDataSource.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchDataSource.kt index df7ed0dd37..cf39ea244e 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchDataSource.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchDataSource.kt @@ -60,11 +60,15 @@ class RoomListSearchDataSource( roomList.updateVisibleRange(visibleRange) } - suspend fun setSearchQuery(searchQuery: String) = coroutineScope { + suspend fun setSearchQuery(searchQuery: String, additionalFilters: RoomListFilter?) = coroutineScope { val filter = if (searchQuery.isBlank()) { RoomListFilter.None } else { - RoomListFilter.NormalizedMatchRoomName(searchQuery) + if (additionalFilters != null) { + RoomListFilter.all(additionalFilters, RoomListFilter.NormalizedMatchRoomName(searchQuery)) + } else { + RoomListFilter.NormalizedMatchRoomName(searchQuery) + } } roomList.updateFilter(filter) } diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchPresenter.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchPresenter.kt index 763fbb23d0..d04eb318c3 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchPresenter.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/RoomListSearchPresenter.kt @@ -39,7 +39,7 @@ class RoomListSearchPresenter( val dataSource = remember { dataSourceFactory.create(coroutineScope) } LaunchedEffect(searchQuery.text) { - dataSource.setSearchQuery(searchQuery.text.toString()) + dataSource.setSearchQuery(searchQuery = searchQuery.text.toString(), additionalFilters = null) } fun handleEvent(event: RoomListSearchEvent) { diff --git a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt index 94c19bb81d..0c6b063705 100644 --- a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt +++ b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt @@ -23,6 +23,9 @@ import io.element.android.libraries.featureflag.api.FeatureFlags import io.element.android.libraries.featureflag.test.FakeFeatureFlagService import io.element.android.libraries.matrix.api.MatrixClient import io.element.android.libraries.matrix.api.permalink.PermalinkParser +import io.element.android.libraries.matrix.api.roomlist.RoomListFilter +import io.element.android.libraries.matrix.api.roomlist.RoomListFilter.Joined +import io.element.android.libraries.matrix.api.roomlist.RoomListFilter.NormalizedMatchRoomName import io.element.android.libraries.matrix.api.roomlist.RoomListService import io.element.android.libraries.matrix.api.search.MessageSearchService import io.element.android.libraries.matrix.test.FakeMatrixClient @@ -142,6 +145,9 @@ class GlobalSearchPresenterTest { testScheduler.advanceUntilIdle() roomList.summaries.emit(listOf(aRoomSummary())) + // The filter is updated to include the search query and only search joined rooms + assertThat(roomList.currentFilter.value).isEqualTo(RoomListFilter.all(Joined, NormalizedMatchRoomName("A query"))) + // Wait for the presenter to emit a loading state before the success state consumeItemsUntilPredicate { it.results is AsyncData.Loading } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/roomlist/RoomListFilter.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/roomlist/RoomListFilter.kt index 44485fed62..f7325fb211 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/roomlist/RoomListFilter.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/roomlist/RoomListFilter.kt @@ -67,6 +67,11 @@ sealed interface RoomListFilter { */ data object Invite : RoomListFilter + /** + * A filter that matches rooms with Joined membership. + */ + data object Joined : RoomListFilter + /** * A filter that matches either Group,People rooms or Space. */ diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListFilterMapper.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListFilterMapper.kt index 0e0d979a1e..c93329f7d5 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListFilterMapper.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListFilterMapper.kt @@ -16,6 +16,7 @@ import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.Deduplicat import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.Favourite import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.Identifiers import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.Invite +import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.Joined import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.NonLeft import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.NonSpace import org.matrix.rustcomponents.sdk.RoomListEntriesDynamicFilterKind.None @@ -73,6 +74,7 @@ internal object RoomListFilterMapper { is RoomListFilter.NormalizedMatchRoomName -> NormalizedMatchRoomName( pattern = filter.pattern ) + RoomListFilter.Joined -> Joined RoomListFilter.Invite -> Invite } }