From bd4c30ed4d1b3e6c092ee454b62b4869e4983697 Mon Sep 17 00:00:00 2001 From: otsmr Date: Tue, 28 Oct 2025 14:28:44 +0100 Subject: [PATCH] fixing ios push notifications --- .../NotificationService.swift | 18 +++++++++++++++--- lib/src/services/api/messages.dart | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ios/NotificationService/NotificationService.swift b/ios/NotificationService/NotificationService.swift index 57de2d5..c2c6048 100644 --- a/ios/NotificationService/NotificationService.swift +++ b/ios/NotificationService/NotificationService.swift @@ -35,6 +35,7 @@ class NotificationService: UNNotificationServiceExtension { bestAttemptContent.body = data!.body bestAttemptContent.threadIdentifier = String(format: "%d", data!.notificationId) } else { + NSLog("Could not decrypt message. Show default.") bestAttemptContent.title = "\(bestAttemptContent.title)" } @@ -81,7 +82,8 @@ func getPushNotificationData(pushData: String) -> ( key: pushKey.key, pushData: pushData) if pushNotification != nil { pushUser = tryPushUser - if pushNotification!.messageID <= pushUser!.lastMessageID { + if isUUIDNewer(pushUser!.lastMessageID, pushNotification!.messageID) + { return ("blocked", "blocked", 0) } break @@ -125,6 +127,16 @@ func getPushNotificationData(pushData: String) -> ( } } +func isUUIDNewer(_ uuid1: String, _ uuid2: String) -> Bool { + guard uuid1.count >= 8, uuid2.count >= 8 else { return true } + let hex1 = String(uuid1.prefix(8)) + let hex2 = String(uuid2.prefix(8)) + guard let timestamp1 = UInt32(hex1, radix: 16), + let timestamp2 = UInt32(hex2, radix: 16) + else { return true } + return timestamp1 > timestamp2 +} + func tryDecryptMessage(key: Data, pushData: EncryptedPushNotification) -> PushNotification? { do { @@ -152,8 +164,8 @@ func tryDecryptMessage(key: Data, pushData: EncryptedPushNotification) -> PushNo func getPushUsers() -> [PushUser]? { // Retrieve the data from secure storage (Keychain) - guard let pushUsersB64 = readFromKeychain(key: "receiving_push_keys") else { - NSLog("No data found for key: receiving_push_keys") + guard let pushUsersB64 = readFromKeychain(key: "push_keys_receiving") else { + NSLog("No data found for key: push_keys_receiving") return nil } guard let pushUsersBytes = Data(base64Encoded: pushUsersB64) else { diff --git a/lib/src/services/api/messages.dart b/lib/src/services/api/messages.dart index b6591f4..2345e02 100644 --- a/lib/src/services/api/messages.dart +++ b/lib/src/services/api/messages.dart @@ -70,7 +70,8 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({ ); Uint8List? pushData; - if (pushNotification != null) { + if (pushNotification != null && receipt.retryCount <= 3) { + /// In case the message has to be resend more than three times, do not show a notification again... pushData = await encryptPushNotification(receipt.contactId, pushNotification); }