diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index a9a645149..bb5a23838 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -38,7 +38,7 @@ final class AppSettings { case notificationSettingsEnabled case swiftUITimelineEnabled case pollsInTimeline - case fuzzySearchEnabled + case dynamicEntriesEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -225,6 +225,6 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.pollsInTimeline, defaultValue: false, storageType: .userDefaults(store)) var pollsInTimelineEnabled - @UserPreference(key: UserDefaultsKeys.fuzzySearchEnabled, defaultValue: true, storageType: .userDefaults(store)) - var fuzzySearchEnabled + @UserPreference(key: UserDefaultsKeys.dynamicEntriesEnabled, defaultValue: true, storageType: .userDefaults(store)) + var dynamicEntriesEnabled } diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift index 19aee6ffb..0b88c3e6d 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift @@ -79,14 +79,14 @@ struct HomeScreenViewState: BindableState { var selectedRoomID: String? - var fuzzySearchEnabled: Bool + var dynamicEntriesEnabled: Bool var visibleRooms: [HomeScreenRoom] { if roomListMode == .skeletons { return placeholderRooms } - if fuzzySearchEnabled || bindings.searchQuery.isEmpty { + if dynamicEntriesEnabled || bindings.searchQuery.isEmpty { return rooms } diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 1f776aa66..f1088a4ca 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -49,7 +49,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol roomSummaryProvider = userSession.clientProxy.roomSummaryProvider inviteSummaryProvider = userSession.clientProxy.inviteSummaryProvider - super.init(initialViewState: HomeScreenViewState(userID: userSession.userID, fuzzySearchEnabled: appSettings.fuzzySearchEnabled), + super.init(initialViewState: HomeScreenViewState(userID: userSession.userID, dynamicEntriesEnabled: appSettings.dynamicEntriesEnabled), imageProvider: userSession.mediaProvider) userSession.callbacks @@ -74,12 +74,12 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol .weakAssign(to: \.state.selectedRoomID, on: self) .store(in: &cancellables) - appSettings.$fuzzySearchEnabled - .weakAssign(to: \.state.fuzzySearchEnabled, on: self) + appSettings.$dynamicEntriesEnabled + .weakAssign(to: \.state.dynamicEntriesEnabled, on: self) .store(in: &cancellables) context.$viewState - .filter { _ in appSettings.fuzzySearchEnabled } + .filter { _ in appSettings.dynamicEntriesEnabled } .map(\.bindings.searchQuery) .debounceAndRemoveDuplicates() .sink { [weak self] searchQuery in diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index 928113a49..9fcd0c7f7 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -49,7 +49,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var notificationSettingsEnabled: Bool { get set } var swiftUITimelineEnabled: Bool { get set } var pollsInTimelineEnabled: Bool { get set } - var fuzzySearchEnabled: Bool { get set } + var dynamicEntriesEnabled: Bool { get set } } extension AppSettings: DeveloperOptionsProtocol { } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index aa5172029..6e525341d 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -39,8 +39,8 @@ struct DeveloperOptionsScreen: View { } Section("Room list") { - Toggle(isOn: $context.fuzzySearchEnabled) { - Text("Fuzzy search") + Toggle(isOn: $context.dynamicEntriesEnabled) { + Text("Dynamic entries") Text("Requires app reboot") } } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 63157c1cf..56e369e50 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -80,16 +80,33 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { self.roomList = roomList do { - listUpdatesSubscriptionResult = roomList.entriesWithDynamicFilter(listener: RoomListEntriesListenerProxy { [weak self] updates in - guard let self else { return } - MXLog.info("\(name): Received list update") - diffsPublisher.send(updates) - }) - - listUpdatesTaskHandle = listUpdatesSubscriptionResult?.entriesStream - - // Forces the listener above to be called with the current state - updateFilterPattern(nil) + if appSettings.dynamicEntriesEnabled { + listUpdatesSubscriptionResult = roomList.entriesWithDynamicFilter(listener: RoomListEntriesListenerProxy { [weak self] updates in + guard let self else { return } + MXLog.info("\(name): Received list update") + diffsPublisher.send(updates) + }) + + listUpdatesTaskHandle = listUpdatesSubscriptionResult?.entriesStream + + // Forces the listener above to be called with the current state + updateFilterPattern(nil) + } else { + let listUpdatesSubscriptionResult = roomList.entries(listener: RoomListEntriesListenerProxy { [weak self] updates in + guard let self else { return } + MXLog.info("\(name): Received list update") + diffsPublisher.send(updates) + }) + + listUpdatesTaskHandle = listUpdatesSubscriptionResult.entriesStream + + rooms = listUpdatesSubscriptionResult.entries.map { roomListEntry in + buildSummaryForRoomListEntry(roomListEntry) + } + + // Manually call it here as the didSet doesn't work from constructors + roomListSubject.send(rooms) + } let stateUpdatesSubscriptionResult = try roomList.loadingState(listener: RoomListStateObserver { [weak self] state in guard let self else { return } @@ -122,9 +139,9 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { return } - guard appSettings.fuzzySearchEnabled else { return } + guard appSettings.dynamicEntriesEnabled else { return } - _ = listUpdatesSubscriptionResult?.dynamicFilter.set(kind: .fuzzyMatchRoomName(pattern: pattern.lowercased())) + _ = listUpdatesSubscriptionResult?.dynamicFilter.set(kind: .normalizedMatchRoomName(pattern: pattern.lowercased())) } // MARK: - Private