From 1e89f6c4fdc5e211ef5256fa7091d2411730ea2b Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Fri, 14 Mar 2025 09:56:28 +1100 Subject: [PATCH] fix some issues on database preparation and potential --- Scripts/LintLocalizableStrings.swift | 9 ++++--- .../Calls/Call Management/SessionCall.swift | 24 ++++++++++++------- .../WebRTCSession+MessageHandling.swift | 8 ++++--- .../PushRegistrationManager.swift | 6 +++-- .../NotificationServiceExtension.swift | 2 +- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Scripts/LintLocalizableStrings.swift b/Scripts/LintLocalizableStrings.swift index 4adf0c16b..f5138dc78 100755 --- a/Scripts/LintLocalizableStrings.swift +++ b/Scripts/LintLocalizableStrings.swift @@ -40,7 +40,8 @@ extension ProjectState { "cameraGrantAccessDescription", "permissionsAppleMusic", "permissionsStorageSave", - "permissionsMicrophoneAccessRequiredIos" + "permissionsMicrophoneAccessRequiredIos", + "permissionsLocalNetworkAccessRequiredIos" ] static let permissionStringsMap: [String: String] = [ "permissionsStorageSend": "NSPhotoLibraryUsageDescription", @@ -48,7 +49,8 @@ extension ProjectState { "cameraGrantAccessDescription": "NSCameraUsageDescription", "permissionsAppleMusic": "NSAppleMusicUsageDescription", "permissionsStorageSave": "NSPhotoLibraryAddUsageDescription", - "permissionsMicrophoneAccessRequiredIos": "NSMicrophoneUsageDescription" + "permissionsMicrophoneAccessRequiredIos": "NSMicrophoneUsageDescription", + "permissionsLocalNetworkAccessRequiredIos": "NSLocalNetworkUsageDescription" ] static let validSourceSuffixes: Set = [".swift", ".m"] static let excludedPaths: Set = [ @@ -318,7 +320,8 @@ enum ScriptAction: String { ProjectState.permissionStrings.forEach { key in guard let nsKey: String = ProjectState.permissionStringsMap[key] else { return } if - let stringsData: Data = try? JSONSerialization.data(withJSONObject: (projectState.localizationFile.strings[key] as! JSON), options: [ .fragmentsAllowed ]), + let json = projectState.localizationFile.strings[key] as? JSON, + let stringsData: Data = try? JSONSerialization.data(withJSONObject: json, options: [ .fragmentsAllowed ]), let stringsJSONString: String = String(data: stringsData, encoding: .utf8) { let updatedStringsJSONString = stringsJSONString.replacingOccurrences(of: "{app_name}", with: "Session") diff --git a/Session/Calls/Call Management/SessionCall.swift b/Session/Calls/Call Management/SessionCall.swift index 944b73cb9..64ce23d57 100644 --- a/Session/Calls/Call Management/SessionCall.swift +++ b/Session/Calls/Call Management/SessionCall.swift @@ -23,7 +23,13 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { var audioMode: AudioMode public let webRTCSession: WebRTCSession let isOutgoing: Bool - var remoteSDP: RTCSessionDescription? = nil + var remoteSDP: RTCSessionDescription? = nil { + didSet { + if hasStartedConnecting, let sdp = remoteSDP { + webRTCSession.handleRemoteSDP(sdp, from: sessionId) // This sends an answer message internally + } + } + } var callInteractionId: Int64? var answerCallAction: CXAnswerCallAction? = nil @@ -214,9 +220,6 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { Log.info(.calls, "Did receive remote sdp.") remoteSDP = sdp - if hasStartedConnecting { - webRTCSession.handleRemoteSDP(sdp, from: sessionId) // This sends an answer message internally - } if mode == .answer { self.updateCurrentConnectionStepIfPossible(AnswerStep.receivedOffer) } @@ -296,10 +299,10 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { guard case .answer = mode else { return } hasStartedConnecting = true + self.updateCurrentConnectionStepIfPossible(AnswerStep.sendingAnswer) if let sdp = remoteSDP { SNLog("[Calls] Got remote sdp already") - self.updateCurrentConnectionStepIfPossible(AnswerStep.sendingAnswer) webRTCSession.handleRemoteSDP(sdp, from: sessionId) // This sends an answer message internally } } @@ -615,9 +618,14 @@ extension SessionCall { connectionStepsRecord[step.index] = true while let nextStep = currentConnectionStep.nextStep, connectionStepsRecord[nextStep.index] { currentConnectionStep = nextStep - updateCallDetailedStatus?( - mode == .offer ? Constants.call_connection_steps_sender[currentConnectionStep.index] : Constants.call_connection_steps_receiver[currentConnectionStep.index] - ) + DispatchQueue.main.async { + self.updateCallDetailedStatus?( + self.mode == .offer ? + Constants.call_connection_steps_sender[self.currentConnectionStep.index] : + Constants.call_connection_steps_receiver[self.currentConnectionStep.index] + ) + } + } } } diff --git a/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift b/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift index 6364e86ab..853e2ba45 100644 --- a/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift +++ b/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift @@ -24,9 +24,11 @@ extension WebRTCSession { else { guard sdp.type == .offer else { return } - self?.sendAnswer(to: sessionId) - .retry(5) - .sinkUntilComplete() + DispatchQueue.global(qos: .userInitiated).async { + self?.sendAnswer(to: sessionId) + .retry(5) + .sinkUntilComplete() + } } }) } diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift index a8bcbd240..25cc97cf5 100644 --- a/Session/Notifications/PushRegistrationManager.swift +++ b/Session/Notifications/PushRegistrationManager.swift @@ -314,8 +314,10 @@ public class PushRegistrationManager: NSObject, PKPushRegistryDelegate { dependencies[singleton: .jobRunner].appDidBecomeActive() - // NOTE: Just start 1-1 poller so that it won't wait for polling group messages - (UIApplication.shared.delegate as? AppDelegate)?.startPollersIfNeeded(shouldStartGroupPollers: false) + dependencies[singleton: .appReadiness].runNowOrWhenAppDidBecomeReady { + // NOTE: Just start 1-1 poller so that it won't wait for polling group messages + (UIApplication.shared.delegate as? AppDelegate)?.startPollersIfNeeded(shouldStartGroupPollers: false) + } call.reportIncomingCallIfNeeded { error in if let error = error { diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 8af99a3ef..0b7a245fe 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -485,7 +485,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension for callMessage: CallMessage, runId: String ) { - if #available(iOSApplicationExtension 14.5, *), Preferences.isCallKitSupported { + if Preferences.isCallKitSupported { guard let caller: String = callMessage.sender, let timestamp = callMessage.sentTimestampMs else { return } let reportCall: () -> () = { [weak self, dependencies] in