store messages in NSE

pull/235/head
Ryan ZHAO 5 years ago
parent 2900366293
commit 1eb47ed960

@ -15,31 +15,36 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler self.contentHandler = contentHandler
notificationContent = (request.content.mutableCopy() as? UNMutableNotificationContent) notificationContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
DispatchQueue.main.async { // The code using DispatchQueue.main.async { self.setUpIfNecessary(){ Modify the notification content } } will somehow cause a freezing when the second PN comes
self.setUpIfNecessary() {
if let notificationContent = self.notificationContent { DispatchQueue.main.sync { self.setUpIfNecessary(){} }
// Modify the notification content here...
let base64EncodedData = notificationContent.userInfo["ENCRYPTED_DATA"] as! String AppReadiness.runNowOrWhenAppDidBecomeReady {
let data = Data(base64Encoded: base64EncodedData)! if let notificationContent = self.notificationContent {
let decrypter = SSKEnvironment.shared.messageDecrypter // Modify the notification content here...
if let envelope = try? MessageWrapper.unwrap(data: data), let data = try? envelope.serializedData() { let base64EncodedData = notificationContent.userInfo["ENCRYPTED_DATA"] as! String
decrypter.decryptEnvelope(envelope, let data = Data(base64Encoded: base64EncodedData)!
envelopeData: data, let decrypter = SSKEnvironment.shared.messageDecrypter
successBlock: { result, transaction in let messageManager = SSKEnvironment.shared.messageManager
if (try? SSKProtoEnvelope.parseData(result.envelopeData)) != nil { if let envelope = try? MessageWrapper.unwrap(data: data), let data = try? envelope.serializedData() {
self.handleDecryptionResult(result: result, notificationContent: notificationContent, transaction: transaction) let wasReceivedByUD = self.wasReceivedByUD(envelope: envelope)
} else { decrypter.decryptEnvelope(envelope,
self.completeWithFailure(content: notificationContent) envelopeData: data,
} successBlock: { result, transaction in
}, if let envelope = try? SSKProtoEnvelope.parseData(result.envelopeData) {
failureBlock: { messageManager.throws_processEnvelope(envelope, plaintextData: result.plaintextData, wasReceivedByUD: wasReceivedByUD, transaction: transaction, serverID: 0)
self.handleDecryptionResult(result: result, notificationContent: notificationContent, transaction: transaction)
} else {
self.completeWithFailure(content: notificationContent) self.completeWithFailure(content: notificationContent)
} }
) },
} else { failureBlock: {
self.completeWithFailure(content: notificationContent) self.completeWithFailure(content: notificationContent)
} }
)
} else {
self.completeWithFailure(content: notificationContent)
} }
} }
} }

Loading…
Cancel
Save