From 31605672e24347428c2a781e05be317c7e4960ac Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 5 Sep 2022 11:27:25 +1000 Subject: [PATCH] fix call threading issues --- .../Call Management/SessionCallManager.swift | 43 +++++++++---------- .../Notifications/PushNotificationAPI.swift | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index e6ec78ce9..e7ab88431 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -104,8 +104,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { } public func reportIncomingCall(_ call: SessionCall, callerName: String, completion: @escaping (Error?) -> Void) { - AssertIsOnMainThread() - let provider = provider ?? Self.sharedProvider(useSystemCallLog: false) // Construct a CXCallUpdate describing the incoming call, including the caller. let update = CXCallUpdate() @@ -139,8 +137,10 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { WebRTCSession.current = nil UserDefaults.sharedLokiProject?.set(false, forKey: "isCallOngoing") if CurrentAppContext().isInBackground() { - // Suspend the database - NotificationCenter.default.post(name: Database.suspendNotification, object: self) + // Stop all jobs except for message sending and when completed suspend the database + JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend) { + NotificationCenter.default.post(name: Database.suspendNotification, object: self) + } } } @@ -186,12 +186,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { // MARK: - UI public func showCallUIForCall(caller: String, uuid: String, mode: CallMode, interactionId: Int64?) { - guard Thread.isMainThread else { - DispatchQueue.main.async { - self.showCallUIForCall(caller: caller, uuid: uuid, mode: mode, interactionId: interactionId) - } - return - } guard let call: SessionCall = Storage.shared.read({ db in SessionCall(db, for: caller, uuid: uuid, mode: mode) }) else { return } @@ -204,20 +198,23 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { } guard CurrentAppContext().isMainAppAndActive else { return } - guard let presentingVC = CurrentAppContext().frontmostViewController() else { - preconditionFailure() // FIXME: Handle more gracefully - } - if let conversationVC: ConversationVC = presentingVC as? ConversationVC, conversationVC.viewModel.threadData.threadId == call.sessionId { - let callVC = CallVC(for: call) - callVC.conversationVC = conversationVC - conversationVC.inputAccessoryView?.isHidden = true - conversationVC.inputAccessoryView?.alpha = 0 - presentingVC.present(callVC, animated: true, completion: nil) - } - else if !Preferences.isCallKitSupported { - let incomingCallBanner = IncomingCallBanner(for: call) - incomingCallBanner.show() + DispatchQueue.main.async { + guard let presentingVC = CurrentAppContext().frontmostViewController() else { + preconditionFailure() // FIXME: Handle more gracefully + } + + if let conversationVC: ConversationVC = presentingVC as? ConversationVC, conversationVC.viewModel.threadData.threadId == call.sessionId { + let callVC = CallVC(for: call) + callVC.conversationVC = conversationVC + conversationVC.inputAccessoryView?.isHidden = true + conversationVC.inputAccessoryView?.alpha = 0 + presentingVC.present(callVC, animated: true, completion: nil) + } + else if !Preferences.isCallKitSupported { + let incomingCallBanner = IncomingCallBanner(for: call) + incomingCallBanner.show() + } } } } diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 11499c28f..be56e92bf 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -28,7 +28,7 @@ public final class PushNotificationAPI : NSObject { } // MARK: - Settings - public static let server = "https://live.apns.getsession.org" + public static let server = "https://dev.apns.getsession.org" public static let serverPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049" private static let maxRetryCount: UInt = 4