From 4d697a3a492014125bd6933c44f4dfe4d130901a Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 10 Oct 2024 15:04:17 +0300 Subject: [PATCH] Introduce a feature flag for the new identity pinning violation notifications feature. --- ElementX/Sources/Application/AppSettings.swift | 4 ++++ ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift | 4 +++- .../DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift | 1 + .../DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index ec0dc26b6..16c74d9fb 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -46,6 +46,7 @@ final class AppSettings { case fuzzyRoomListSearchEnabled case pinningEnabled case enableOnlySignedDeviceIsolationMode + case identityPinningViolationNotificationsEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -278,6 +279,9 @@ final class AppSettings { enum SlidingSyncDiscovery: Codable { case proxy, native, forceNative } @UserPreference(key: UserDefaultsKeys.slidingSyncDiscovery, defaultValue: .native, storageType: .userDefaults(store)) var slidingSyncDiscovery: SlidingSyncDiscovery + + @UserPreference(key: UserDefaultsKeys.identityPinningViolationNotificationsEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store)) + var identityPinningViolationNotificationsEnabled #endif diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 36f3bb723..956ae8210 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -142,7 +142,9 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol } .store(in: &cancellables) - let identityStatusChangesPublisher = roomProxy.identityStatusChangesPublisher.receive(on: DispatchQueue.main) + let identityStatusChangesPublisher = roomProxy.identityStatusChangesPublisher + .receive(on: DispatchQueue.main) + .filter { [weak self] _ in self?.appSettings.identityPinningViolationNotificationsEnabled ?? false } Task { [weak self] in for await changes in identityStatusChangesPublisher.values { diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index d2f9f7a4b..4bff8d369 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 hideTimelineMedia: Bool { get set } var enableOnlySignedDeviceIsolationMode: Bool { get set } var elementCallBaseURLOverride: URL? { get set } + var identityPinningViolationNotificationsEnabled: 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 878efcb09..df1afd540 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -49,6 +49,10 @@ struct DeveloperOptionsScreen: View { Toggle(isOn: $context.hideTimelineMedia) { Text("Hide image & video previews") } + + Toggle(isOn: $context.identityPinningViolationNotificationsEnabled) { + Text("Identity pinning violation notifications") + } } Section {