Debug code for push

This commit is contained in:
Thomas Ricouard 2023-01-11 11:54:48 +01:00
parent 1d8fa7902e
commit f1219d319b

View File

@ -21,6 +21,7 @@ class NotificationService: UNNotificationServiceExtension {
guard let encodedPayload = bestAttemptContent.userInfo["m"] as? String, guard let encodedPayload = bestAttemptContent.userInfo["m"] as? String,
let payload = Data(base64Encoded: encodedPayload.URLSafeBase64ToBase64()) else { let payload = Data(base64Encoded: encodedPayload.URLSafeBase64ToBase64()) else {
bestAttemptContent.title = "Failied to decode payload as base 64"
contentHandler(bestAttemptContent) contentHandler(bestAttemptContent)
return return
} }
@ -28,12 +29,14 @@ class NotificationService: UNNotificationServiceExtension {
guard let encodedPublicKey = bestAttemptContent.userInfo["k"] as? String, guard let encodedPublicKey = bestAttemptContent.userInfo["k"] as? String,
let publicKeyData = Data(base64Encoded: encodedPublicKey.URLSafeBase64ToBase64()), let publicKeyData = Data(base64Encoded: encodedPublicKey.URLSafeBase64ToBase64()),
let publicKey = try? P256.KeyAgreement.PublicKey(x963Representation: publicKeyData) else { let publicKey = try? P256.KeyAgreement.PublicKey(x963Representation: publicKeyData) else {
bestAttemptContent.title = "Failied to inflate public key"
contentHandler(bestAttemptContent) contentHandler(bestAttemptContent)
return return
} }
guard let encodedSalt = bestAttemptContent.userInfo["s"] as? String, guard let encodedSalt = bestAttemptContent.userInfo["s"] as? String,
let salt = Data(base64Encoded: encodedSalt.URLSafeBase64ToBase64()) else { let salt = Data(base64Encoded: encodedSalt.URLSafeBase64ToBase64()) else {
bestAttemptContent.title = "Failied to inflate salt"
contentHandler(bestAttemptContent) contentHandler(bestAttemptContent)
return return
} }
@ -44,6 +47,7 @@ class NotificationService: UNNotificationServiceExtension {
privateKey: privateKey, privateKey: privateKey,
publicKey: publicKey), publicKey: publicKey),
let notification = try? JSONDecoder().decode(MastodonPushNotification.self, from: plaintextData) else { let notification = try? JSONDecoder().decode(MastodonPushNotification.self, from: plaintextData) else {
bestAttemptContent.title = "Failied to JSON decode the Notification"
contentHandler(bestAttemptContent) contentHandler(bestAttemptContent)
return return
} }