Only show joined rooms in the search results

Rooms the user is invited to, or has knocked on, are handled by the chats
list and aren't somewhere search should lead. The search screen now asks
the room summary provider for joined rooms only.
This commit is contained in:
Stefan Ceriu
2026-09-10 17:27:32 +03:00
parent 482cc0fee8
commit 82e666bfe1
2 changed files with 20 additions and 1 deletions
@@ -183,7 +183,7 @@ class SearchScreenViewModel: SearchScreenViewModelType, SearchScreenViewModelPro
switch mode {
case .rooms:
searchedQueries[mode] = searchQuery
roomSummaryProvider.setFilter(.search(query: searchQuery))
roomSummaryProvider.setFilter(.search(query: searchQuery, joinedOnly: true))
case .messages:
setQueryTask = Task { [weak self] in
// Debounce message queries; superseded keystrokes cancel this before it commits.
@@ -68,6 +68,25 @@ struct SearchScreenViewModelTests {
#expect(!searchService.setQueryCalled)
}
@Test
func searchingExcludesRoomsThatAreNotJoined() async throws {
let roomSummaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms + .mockInvites)))
let clientProxy = ClientProxyMock(.init())
clientProxy.searchService = searchService
let viewModel = SearchScreenViewModel(roomSummaryProvider: roomSummaryProvider,
clientProxy: clientProxy,
mediaProvider: MediaProviderMock(.init()),
userIndicatorController: userIndicatorController,
appSettings: appSettings)
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.rooms)) { !$0.isEmpty }
viewModel.context.searchQuery = "room"
try await deferred.fulfill()
#expect(roomSummaryProvider.setFilterReceivedFilter == .search(query: "room", joinedOnly: true))
#expect(!viewModel.context.viewState.rooms.contains { $0.title == "First room" })
}
@Test
func messageSearch() async throws {
let deferred = deferFulfillment(setQuerySubject) { $0 == "Foundation" }