diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 3fb59a4cf..2eeba82f7 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -61,12 +61,18 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension } private func handleNotification(_ notificationContent: UNMutableNotificationContent, isPerformingResetup: Bool) { + let userSessionId: String = getUserHexEncodedPublicKey(using: dependencies) let (maybeData, metadata, result) = PushNotificationAPI.processNotification( notificationContent: notificationContent, using: dependencies ) - guard metadata.accountId == getUserHexEncodedPublicKey(using: dependencies) else { + /// There is an annoying issue where clearing account data and creating a new account can result in the user receiving push notifications + /// for the new account but the NotificationServiceExtension having cached state based on the old account + /// + /// In order to avoid this we check if the account the notification was sent to matches the current users sessionId and if it doesn't (and the + /// notification is for a message stored in one of the users namespaces) then try to re-setup the notification extension + guard !metadata.namespace.isCurrentUserNamespace || metadata.accountId == userSessionId else { guard !isPerformingResetup else { Log.error("Received notification for an accountId that isn't the current user, resetup failed.") return self.completeSilenty(handledNotification: false) diff --git a/SessionSnodeKit/Types/SnodeAPINamespace.swift b/SessionSnodeKit/Types/SnodeAPINamespace.swift index 5718edd83..56a6fdb52 100644 --- a/SessionSnodeKit/Types/SnodeAPINamespace.swift +++ b/SessionSnodeKit/Types/SnodeAPINamespace.swift @@ -68,6 +68,16 @@ public extension SnodeAPI { } } + public var isCurrentUserNamespace: Bool { + switch self { + case .default, .configUserProfile, .configContacts, .configConvoInfoVolatile, .configUserGroups: + return true + + case .configClosedGroupInfo, .legacyClosedGroup, .unknown, .all: + return false + } + } + public var isConfigNamespace: Bool { switch self { case .configUserProfile, .configContacts, .configConvoInfoVolatile, .configUserGroups,