NSE tweaks to ensure code paths all behave as expected

pull/981/head
Morgan Pretty 11 months ago
parent 1ee7548c0a
commit 27a3dff06b

@ -169,7 +169,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
case (true, false): case (true, false):
try MessageReceiver.insertCallInfoMessage(db, for: callMessage) try MessageReceiver.insertCallInfoMessage(db, for: callMessage)
self?.handleSuccessForIncomingCall(db, for: callMessage) return self?.handleSuccessForIncomingCall(db, for: callMessage)
} }
// Perform any required post-handling logic // Perform any required post-handling logic
@ -357,21 +357,25 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
if #available(iOSApplicationExtension 14.5, *), Preferences.isCallKitSupported { if #available(iOSApplicationExtension 14.5, *), Preferences.isCallKitSupported {
guard let caller: String = callMessage.sender, let timestamp = callMessage.sentTimestamp else { return } guard let caller: String = callMessage.sender, let timestamp = callMessage.sentTimestamp else { return }
let payload: JSON = [ let reportCall: () -> () = { [weak self] in
"uuid": callMessage.uuid, // stringlint:disable let payload: JSON = [
"caller": caller, // stringlint:disable "uuid": callMessage.uuid, // stringlint:disable
"timestamp": timestamp // stringlint:disable "caller": caller, // stringlint:disable
] "timestamp": timestamp // stringlint:disable
]
CXProvider.reportNewIncomingVoIPPushPayload(payload) { error in
if let error = error { CXProvider.reportNewIncomingVoIPPushPayload(payload) { error in
self.handleFailureForVoIP(db, for: callMessage) if let error = error {
Log.error("Failed to notify main app of call message: \(error).") Log.error("Failed to notify main app of call message: \(error).")
} Storage.shared.read { db in
else { self?.handleFailureForVoIP(db, for: callMessage)
Log.info("Successfully notified main app of call message.") }
UserDefaults.sharedLokiProject?[.lastCallPreOffer] = Date() }
self.completeSilenty() else {
Log.info("Successfully notified main app of call message.")
UserDefaults.sharedLokiProject?[.lastCallPreOffer] = Date()
self?.completeSilenty()
}
} }
} }
} }
@ -408,7 +412,11 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
} }
semaphore.wait() semaphore.wait()
Log.info("Add remote notification request.") Log.info("Add remote notification request.")
completeSilenty()
db.afterNextTransaction(
onCommit: { [weak self] _ in self?.completeSilenty() },
onRollback: { [weak self] _ in self?.completeSilenty() }
)
} }
private func handleFailure(for content: UNMutableNotificationContent, error: NotificationError) { private func handleFailure(for content: UNMutableNotificationContent, error: NotificationError) {

Loading…
Cancel
Save