diff --git a/Session/Calls/Call Management/SessionCall.swift b/Session/Calls/Call Management/SessionCall.swift index f5969ce7d..bacefe88a 100644 --- a/Session/Calls/Call Management/SessionCall.swift +++ b/Session/Calls/Call Management/SessionCall.swift @@ -296,10 +296,10 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { func endSessionCall() { guard !hasEnded else { return } - let sessionId: String = self.sessionId - webRTCSession.hangUp() - webRTCSession.endCall(with: sessionId) + dependencies[singleton: .appReadiness].runNowOrWhenAppDidBecomeReady { [webRTCSession, sessionId] in + webRTCSession.endCall(with: sessionId) + } hasEnded = true } diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index 68499cc3c..efd1eb13f 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -230,7 +230,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { else { return } if - let conversationVC: ConversationVC = (presentingVC as? TopBannerController)?.wrappedViewController() as? ConversationVC, + let conversationVC: ConversationVC = presentingVC as? ConversationVC, conversationVC.viewModel.threadData.threadId == call.sessionId { let callVC = CallVC(for: call, using: dependencies) @@ -301,7 +301,9 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { dependencies[defaults: .appGroup, key: .lastCallPreOffer] = nil if dependencies[singleton: .appContext].isNotInForeground { - dependencies[singleton: .currentUserPoller].stop() + dependencies[singleton: .appReadiness].runNowOrWhenAppDidBecomeReady { [dependencies] in + dependencies[singleton: .currentUserPoller].stop() + } Log.flush() } } diff --git a/Session/Calls/WebRTC/WebRTCSession.swift b/Session/Calls/WebRTC/WebRTCSession.swift index fb09df06a..390367dea 100644 --- a/Session/Calls/WebRTC/WebRTCSession.swift +++ b/Session/Calls/WebRTC/WebRTCSession.swift @@ -365,7 +365,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { public func endCall(with sessionId: String) { return dependencies[singleton: .storage] - .writePublisher { [dependencies] db -> Network.PreparedRequest in + .writePublisher { [dependencies, uuid] db -> Network.PreparedRequest in guard let thread: SessionThread = try SessionThread.fetchOne(db, id: sessionId) else { throw WebRTCSessionError.noThread } @@ -376,7 +376,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { .preparedSend( db, message: CallMessage( - uuid: self.uuid, + uuid: uuid, kind: .endCall, sdps: [] ) diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift index ec1ec5ef5..3e36c2513 100644 --- a/Session/Notifications/PushRegistrationManager.swift +++ b/Session/Notifications/PushRegistrationManager.swift @@ -295,13 +295,11 @@ public class PushRegistrationManager: NSObject, PKPushRegistryDelegate { dependencies[singleton: .jobRunner].appDidBecomeActive() - dependencies[singleton: .appReadiness].runNowOrWhenAppDidBecomeReady { - + dependencies[singleton: .appReadiness].runNowOrWhenAppDidBecomeReady { [dependencies] in + // NOTE: Just start 1-1 poller so that it won't wait for polling group messages + dependencies[singleton: .currentUserPoller].startIfNeeded(forceStartInBackground: true) } - // NOTE: Just start 1-1 poller so that it won't wait for polling group messages - dependencies[singleton: .currentUserPoller].startIfNeeded(forceStartInBackground: true) - call.reportIncomingCallIfNeeded { error in if let error = error { Log.error(.calls, "Failed to report incoming call to CallKit due to error: \(error)")