FF to enable filtering notifications by push rules (#1412)

* filtering notification by push rules

* changelog

* Apply suggestions from code review

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
Mauro
2023-07-27 16:12:52 +02:00
committed by GitHub
parent 232a33626a
commit ec92cfeecb
8 changed files with 24 additions and 5 deletions

View File

@@ -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

View File

@@ -15,5 +15,5 @@
//
enum SharedUserDefaultsKeys: String {
case isEncryptionSyncEnabled
case filterNotificationsByPushRulesEnabled
}

View File

@@ -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 { }

View File

@@ -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") {

View File

@@ -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")

View File

@@ -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
}

View File

@@ -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? {

1
changelog.d/1172.bugfix Normal file
View File

@@ -0,0 +1 @@
Added an FF to enable push rules filtering. Also invitation notifications will now be always displayed reliably.