mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
Start a foreground search backfill request when entering the message search tab
This commit is contained in:
@@ -102,8 +102,12 @@ class SearchScreenViewModel: SearchScreenViewModelType, SearchScreenViewModelPro
|
||||
// Re-run the search when switching tabs so the newly active tab reflects the current query.
|
||||
let searchModeStream = context.observe(\.viewState.bindings.searchMode).removeDuplicates()
|
||||
searchModeObservationTask = Task { [weak self] in
|
||||
for await _ in searchModeStream {
|
||||
for await searchMode in searchModeStream {
|
||||
guard let self else { return }
|
||||
// Opening the messages tab signals the user actually wants history to be searchable.
|
||||
if searchMode == .messages {
|
||||
clientProxy.startSearchBackfill(strategy: .foreground)
|
||||
}
|
||||
updateFilter(for: state.bindings.searchQuery)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ struct SearchScreenViewModelTests {
|
||||
let setQuerySubject = PassthroughSubject<String, Never>()
|
||||
/// Fires each time an indicator is submitted.
|
||||
let submitIndicatorSubject = PassthroughSubject<Void, Never>()
|
||||
/// Fires each time a search backfill is started, with whether it used the foreground strategy.
|
||||
let startSearchBackfillSubject = PassthroughSubject<Bool, Never>()
|
||||
|
||||
var context: SearchScreenViewModelType.Context {
|
||||
viewModel.context
|
||||
@@ -42,6 +44,9 @@ struct SearchScreenViewModelTests {
|
||||
|
||||
let clientProxy = ClientProxyMock(.init())
|
||||
clientProxy.searchService = searchService
|
||||
clientProxy.startSearchBackfillStrategyClosure = { [startSearchBackfillSubject] strategy in
|
||||
startSearchBackfillSubject.send(strategy == .foreground)
|
||||
}
|
||||
let staticRoomSummaryProvider = RoomSummaryProviderMock()
|
||||
staticRoomSummaryProvider.roomListPublisher = staticRoomListSubject.asCurrentValuePublisher()
|
||||
clientProxy.staticRoomSummaryProvider = staticRoomSummaryProvider
|
||||
@@ -97,6 +102,13 @@ struct SearchScreenViewModelTests {
|
||||
#expect(searchService.setQueryReceivedQuery == "Foundation")
|
||||
}
|
||||
|
||||
@Test
|
||||
func openingMessagesTabStartsSearchBackfill() async throws {
|
||||
let deferred = deferFulfillment(startSearchBackfillSubject) { $0 }
|
||||
context.searchMode = .messages
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
@Test
|
||||
func messageSearchFailureShowsErrorIndicator() async throws {
|
||||
searchService.setQueryClosure = { _ in .failure(.sdkError(SearchScreenViewModelTestsError.failed)) }
|
||||
|
||||
Reference in New Issue
Block a user