Skip to content

Commit

Permalink
Refresh notification service on crypto change
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Feb 2, 2023
1 parent 84ecbf6 commit ca77f36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion RiotNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class NotificationService: UNNotificationServiceExtension {
private var ongoingVoIPPushRequests: [String: Bool] = [:]

private var userAccount: MXKAccount?
#if DEBUG
private var isCryptoSDKEnabled = false
#endif

/// Best attempt contents. Will be updated incrementally, if something fails during the process, this best attempt content will be showed as notification. Keys are eventId's
private var bestAttemptContents: [String: UNMutableNotificationContent] = [:]
Expand Down Expand Up @@ -195,7 +198,7 @@ class NotificationService: UNNotificationServiceExtension {
self.userAccount = MXKAccountManager.shared()?.activeAccounts.first
if let userAccount = userAccount {
Self.backgroundServiceInitQueue.sync {
if NotificationService.backgroundSyncService?.credentials != userAccount.mxCredentials {
if hasChangedCryptoSDK() || NotificationService.backgroundSyncService?.credentials != userAccount.mxCredentials {
MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: BEFORE")
self.logMemory()
NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials, persistTokenDataHandler: { persistTokenDataHandler in
Expand All @@ -214,6 +217,19 @@ class NotificationService: UNNotificationServiceExtension {
}
}

/// Determine whether we have switched from using crypto v1 to v2 or vice versa which will require
/// rebuilding `MXBackgroundSyncService`
private func hasChangedCryptoSDK() -> Bool {
#if DEBUG
if isCryptoSDKEnabled != RiotSettings.shared.enableCryptoSDK {
isCryptoSDKEnabled = RiotSettings.shared.enableCryptoSDK
return true
}
#endif

return false
}

/// Attempts to preprocess payload and attach room display name to the best attempt content
/// - Parameters:
/// - eventId: Event identifier to mutate best attempt content
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7332.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CryptoV2: Refresh notification service on crypto change

0 comments on commit ca77f36

Please sign in to comment.