From b614f43d003f73082719dd5a296c79e1f97a1751 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 17 Jun 2024 12:57:27 +0300 Subject: [PATCH] Add a feature flag for fuzzy room list searching --- ElementX/Sources/Application/AppSettings.swift | 4 ++++ .../DeveloperOptionsScreenModels.swift | 1 + .../View/DeveloperOptionsScreen.swift | 4 ++++ ElementX/Sources/Services/Client/ClientProxy.swift | 11 ++++++++--- .../Room/RoomSummary/RoomSummaryProvider.swift | 11 +++++++++-- .../Services/UserSession/UserSessionStore.swift | 3 ++- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 33a970149..29cf76897 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -45,6 +45,7 @@ final class AppSettings { // Feature flags case publicSearchEnabled case draftRestoringEnabled + case fuzzyRoomListSearchEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -272,6 +273,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.draftRestoringEnabled, defaultValue: false, storageType: .userDefaults(store)) var draftRestoringEnabled + + @UserPreference(key: UserDefaultsKeys.fuzzyRoomListSearchEnabled, defaultValue: false, storageType: .userDefaults(store)) + var fuzzyRoomListSearchEnabled #endif diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index 197465f10..508ea1f85 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -48,6 +48,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var hideUnreadMessagesBadge: Bool { get set } var draftRestoringEnabled: Bool { get set } var elementCallBaseURL: URL { get set } + var fuzzyRoomListSearchEnabled: 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 b0f3ab8a3..39c8e6465 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -31,6 +31,10 @@ struct DeveloperOptionsScreen: View { Toggle(isOn: $context.hideUnreadMessagesBadge) { Text("Hide grey dots") } + + Toggle(isOn: $context.fuzzyRoomListSearchEnabled) { + Text("Fuzzy searching") + } } Section("Room") { diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index a537f7338..dce023b12 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -24,6 +24,7 @@ import MatrixRustSDK class ClientProxy: ClientProxyProtocol { private let client: ClientProtocol private let networkMonitor: NetworkMonitorProtocol + private let appSettings: AppSettings private let mediaLoader: MediaLoaderProtocol private let clientQueue: DispatchQueue @@ -123,9 +124,11 @@ class ClientProxy: ClientProxyProtocol { private let sendQueueStatusSubject = CurrentValueSubject(false) init(client: ClientProtocol, - networkMonitor: NetworkMonitorProtocol) async { + networkMonitor: NetworkMonitorProtocol, + appSettings: AppSettings) async { self.client = client self.networkMonitor = networkMonitor + self.appSettings = appSettings clientQueue = .init(label: "ClientProxyQueue", attributes: .concurrent) @@ -726,13 +729,15 @@ class ClientProxy: ClientProxyProtocol { eventStringBuilder: eventStringBuilder, name: "AllRooms", shouldUpdateVisibleRange: true, - notificationSettings: notificationSettings) + notificationSettings: notificationSettings, + appSettings: appSettings) try await roomSummaryProvider?.setRoomList(roomListService.allRooms()) alternateRoomSummaryProvider = RoomSummaryProvider(roomListService: roomListService, eventStringBuilder: eventStringBuilder, name: "MessageForwarding", - notificationSettings: notificationSettings) + notificationSettings: notificationSettings, + appSettings: appSettings) try await alternateRoomSummaryProvider?.setRoomList(roomListService.allRooms()) self.syncService = syncService diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 4eeefd97c..522a9a417 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -24,6 +24,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { private let name: String private let shouldUpdateVisibleRange: Bool private let notificationSettings: NotificationSettingsProxyProtocol + private let appSettings: AppSettings private let roomListPageSize = 200 @@ -65,13 +66,15 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { eventStringBuilder: RoomEventStringBuilder, name: String, shouldUpdateVisibleRange: Bool = false, - notificationSettings: NotificationSettingsProxyProtocol) { + notificationSettings: NotificationSettingsProxyProtocol, + appSettings: AppSettings) { self.roomListService = roomListService serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider", qos: .default) self.eventStringBuilder = eventStringBuilder self.name = name self.shouldUpdateVisibleRange = shouldUpdateVisibleRange self.notificationSettings = notificationSettings + self.appSettings = appSettings diffsPublisher .receive(on: serialDispatchQueue) @@ -148,7 +151,11 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { case .excludeAll: _ = listUpdatesSubscriptionResult?.controller.setFilter(kind: .none) case let .search(query): - let filters: [RoomListEntriesDynamicFilterKind] = [.normalizedMatchRoomName(pattern: query), .nonLeft] + let filters: [RoomListEntriesDynamicFilterKind] = if appSettings.fuzzyRoomListSearchEnabled { + [.fuzzyMatchRoomName(pattern: query), .nonLeft] + } else { + [.normalizedMatchRoomName(pattern: query), .nonLeft] + } _ = listUpdatesSubscriptionResult?.controller.setFilter(kind: .all(filters: filters)) case let .all(filters): var filters = filters.map(\.rustFilter) diff --git a/ElementX/Sources/Services/UserSession/UserSessionStore.swift b/ElementX/Sources/Services/UserSession/UserSessionStore.swift index 7b873077e..4f108f689 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionStore.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionStore.swift @@ -148,7 +148,8 @@ class UserSessionStore: UserSessionStoreProtocol { private func setupProxyForClient(_ client: Client) async -> ClientProxyProtocol { await ClientProxy(client: client, - networkMonitor: ServiceLocator.shared.networkMonitor) + networkMonitor: ServiceLocator.shared.networkMonitor, + appSettings: ServiceLocator.shared.settings) } private func deleteSessionDirectory(for credentials: KeychainCredentials) {