diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 5d27f601f..e476b9a5e 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -428,17 +428,33 @@ public enum PushNotificationAPI { ), let notification: BencodeResponse = try? BencodeDecoder(using: dependencies) .decode(BencodeResponse.self, from: decryptedData) - else { return (nil, .invalid, .failure) } + else { + SNLog("Failed to decrypt or decode notification") + return (nil, .invalid, .failure) + } // If the metadata says that the message was too large then we should show the generic // notification (this is a valid case) - guard !notification.info.dataTooLong else { return (nil, notification.info, .successTooLong) } + guard !notification.info.dataTooLong else { + SNLog("Ignoring notification due to data being too long") + return (nil, notification.info, .successTooLong) + } + + // Only show notifcations for messages from default namespace + // TODO: Add group messages namespace + guard notification.info.namespace == .default else { + SNLog("Ignoring notification due to namespace being \(notification.info.namespace) instead of default") + return (nil, notification.info, .failureNoContent) + } // Check that the body we were given is valid guard let notificationData: Data = notification.data, notification.info.dataLength == notificationData.count - else { return (nil, notification.info, .failure) } + else { + SNLog("Get notification data failed") + return (nil, notification.info, .failureNoContent) + } // Success, we have the notification content return (notificationData, notification.info, .success) diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 310144c92..376a3302c 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -76,7 +76,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension switch result { // If we got an explicit failure, or we got a success but no content then show // the fallback notification - case .success, .legacySuccess, .failure, .legacyFailure: + case .success, .legacySuccess, .failure: return self.handleFailure(for: notificationContent, error: .processing(result)) // Just log if the notification was too long (a ~2k message should be able to fit so @@ -92,6 +92,10 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension case .failureNoContent: Log.warn("Failed due to missing notification content.") return self.completeSilenty(handledNotification: false) + + case .legacyFailure: + Log.warn("Received a notification without a valid payload.") + return self.completeSilenty(handledNotification: false) } }