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 0e7a48d961
commit 4b14617a8e
8 changed files with 24 additions and 5 deletions
@@ -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")
+4
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
}
+8 -3
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? {