Merge branch 'dev' into call-detailed-info

pull/1061/head
Ryan ZHAO 3 months ago
commit 577437138a

@ -428,17 +428,27 @@ 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)
}
// Check that the body we were given is valid // Check that the body we were given is valid and not empty
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) } !notificationData.isEmpty
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