diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 012ef0662..6e252f36a 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -189,6 +189,10 @@ final class AppSettings { /// Tag describing which set of device specific rules a pusher executes. @UserPreference(key: UserDefaultsKeys.pusherProfileTag, storageType: .userDefaults(store)) var pusherProfileTag: String? + + /// Allows notifications to be filtered based on the push context of the room + @UserPreference(key: SharedUserDefaultsKeys.filterNotificationsByPushRulesEnabled, defaultValue: false, storageType: .userDefaults(store)) + var filterNotificationsByPushRulesEnabled // MARK: - Other diff --git a/ElementX/Sources/Other/SharedUserDefaultsKeys.swift b/ElementX/Sources/Other/SharedUserDefaultsKeys.swift index 164118e55..a941785b4 100644 --- a/ElementX/Sources/Other/SharedUserDefaultsKeys.swift +++ b/ElementX/Sources/Other/SharedUserDefaultsKeys.swift @@ -15,5 +15,5 @@ // enum SharedUserDefaultsKeys: String { - case isEncryptionSyncEnabled + case filterNotificationsByPushRulesEnabled } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index a3255f19d..a11123ad5 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -49,6 +49,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var notificationSettingsEnabled: Bool { get set } var swiftUITimelineEnabled: Bool { get set } var pollsInTimelineEnabled: Bool { get set } + var filterNotificationsByPushRulesEnabled: 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 58f74e649..6b74d1323 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -42,6 +42,10 @@ struct DeveloperOptionsScreen: View { Toggle(isOn: $context.notificationSettingsEnabled) { Text("Show notification settings") } + + Toggle(isOn: $context.filterNotificationsByPushRulesEnabled) { + Text("Filter notifications by push rules") + } } Section("Room creation") { diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index 6b53faa17..91589e8be 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -71,7 +71,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension { MXLog.info("\(tag) run with roomId: \(roomId), eventId: \(eventId)") do { - let userSession = try NSEUserSession(credentials: credentials) + let userSession = try NSEUserSession(credentials: credentials, filterByPushRulesEnabled: settings.filterNotificationsByPushRulesEnabled) self.userSession = userSession guard let itemProxy = await userSession.notificationItemProxy(roomID: roomId, eventID: eventId) else { MXLog.info("\(tag) no notification for the event, discard") diff --git a/NSE/Sources/Other/NSESettings.swift b/NSE/Sources/Other/NSESettings.swift index d0dd2cbb8..c0ad21fc9 100644 --- a/NSE/Sources/Other/NSESettings.swift +++ b/NSE/Sources/Other/NSESettings.swift @@ -21,4 +21,8 @@ final class NSESettings { /// UserDefaults to be used on reads and writes. private static var store: UserDefaults! = UserDefaults(suiteName: suiteName) + + /// Allows notifications to be filtered based on the push context of the room + @UserPreference(key: SharedUserDefaultsKeys.filterNotificationsByPushRulesEnabled, defaultValue: false, storageType: .userDefaults(store)) + var filterNotificationsByPushRulesEnabled } diff --git a/NSE/Sources/Other/NSEUserSession.swift b/NSE/Sources/Other/NSEUserSession.swift index d7f99c400..a129f5c97 100644 --- a/NSE/Sources/Other/NSEUserSession.swift +++ b/NSE/Sources/Other/NSEUserSession.swift @@ -25,7 +25,7 @@ final class NSEUserSession { imageCache: .onlyOnDisk, backgroundTaskService: nil) - init(credentials: KeychainCredentials) throws { + init(credentials: KeychainCredentials, filterByPushRulesEnabled: Bool) throws { userID = credentials.userID baseClient = try ClientBuilder() .basePath(path: URL.sessionsBaseDirectory.path) @@ -34,10 +34,15 @@ final class NSEUserSession { try baseClient.restoreSession(session: credentials.restorationToken.session) - notificationClient = try baseClient + var notificationClientBuilder = try baseClient .notificationClient() .retryDecryption(withCrossProcessLock: true) - .finish() + + if filterByPushRulesEnabled { + notificationClientBuilder = notificationClientBuilder.filterByPushRules() + } + + notificationClient = notificationClientBuilder.finish() } func notificationItemProxy(roomID: String, eventID: String) async -> NotificationItemProxyProtocol? { diff --git a/changelog.d/1172.bugfix b/changelog.d/1172.bugfix new file mode 100644 index 000000000..ea453296f --- /dev/null +++ b/changelog.d/1172.bugfix @@ -0,0 +1 @@ +Added an FF to enable push rules filtering. Also invitation notifications will now be always displayed reliably. \ No newline at end of file