Merge pull request #358 from RyanRory/notification-patch

Fix a case for PNs with no content
pull/1061/head
Morgan Pretty 3 months ago committed by GitHub
commit 0cb4d4184c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -428,17 +428,33 @@ public enum PushNotificationAPI {
), ),
let notification: BencodeResponse<NotificationMetadata> = try? BencodeDecoder(using: dependencies) let notification: BencodeResponse<NotificationMetadata> = try? BencodeDecoder(using: dependencies)
.decode(BencodeResponse<NotificationMetadata>.self, from: decryptedData) .decode(BencodeResponse<NotificationMetadata>.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 // If the metadata says that the message was too large then we should show the generic
// notification (this is a valid case) // 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 // Check that the body we were given is valid
guard guard
let notificationData: Data = notification.data, let notificationData: Data = notification.data,
notification.info.dataLength == notificationData.count 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 // Success, we have the notification content
return (notificationData, notification.info, .success) return (notificationData, notification.info, .success)

@ -76,7 +76,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
switch result { switch result {
// If we got an explicit failure, or we got a success but no content then show // If we got an explicit failure, or we got a success but no content then show
// the fallback notification // the fallback notification
case .success, .legacySuccess, .failure, .legacyFailure: case .success, .legacySuccess, .failure:
return self.handleFailure(for: notificationContent, error: .processing(result)) 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 // 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: case .failureNoContent:
Log.warn("Failed due to missing notification content.") Log.warn("Failed due to missing notification content.")
return self.completeSilenty(handledNotification: false) return self.completeSilenty(handledNotification: false)
case .legacyFailure:
Log.warn("Received a notification without a valid payload.")
return self.completeSilenty(handledNotification: false)
} }
} }

Loading…
Cancel
Save