Skip to content

Commit

Permalink
FF to enable filtering notifications by push rules (#1412)
Browse files Browse the repository at this point in the history
* filtering notification by push rules

* changelog

* Apply suggestions from code review

Co-authored-by: Doug <[email protected]>

---------

Co-authored-by: Doug <[email protected]>
  • Loading branch information
Velin92 and pixlwave authored Jul 27, 2023
1 parent 0e7a48d commit 4b14617
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Other/SharedUserDefaultsKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//

enum SharedUserDefaultsKeys: String {
case isEncryptionSyncEnabled
case filterNotificationsByPushRulesEnabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion NSE/Sources/NotificationServiceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions NSE/Sources/Other/NSESettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 8 additions & 3 deletions NSE/Sources/Other/NSEUserSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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? {
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1172.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added an FF to enable push rules filtering. Also invitation notifications will now be always displayed reliably.

0 comments on commit 4b14617

Please sign in to comment.