From 83a0849f667c50b62d4ec210602a8f93c00b55a8 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Fri, 29 Nov 2024 15:39:08 +1100
Subject: [PATCH 01/13] add some more logs for testing and debug
---
Session.xcodeproj/project.pbxproj | 4 ++--
Session/Calls/Call Management/SessionCallManager.swift | 2 +-
Session/Notifications/PushRegistrationManager.swift | 2 ++
.../Message Handling/MessageReceiver+Calls.swift | 1 +
4 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index 2e50a323b..ea30ead1a 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7816,7 +7816,7 @@
"$(SRCROOT)",
);
LLVM_LTO = NO;
- MARKETING_VERSION = 2.8.2;
+ MARKETING_VERSION = 2.8.3;
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger";
@@ -7887,7 +7887,7 @@
"$(SRCROOT)",
);
LLVM_LTO = NO;
- MARKETING_VERSION = 2.8.2;
+ MARKETING_VERSION = 2.8.3;
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger";
PRODUCT_NAME = Session;
diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift
index 7235ec02a..45427383e 100644
--- a/Session/Calls/Call Management/SessionCallManager.swift
+++ b/Session/Calls/Call Management/SessionCallManager.swift
@@ -113,7 +113,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
// Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate()
update.localizedCallerName = callerName
- update.remoteHandle = CXHandle(type: .generic, value: call.callId.uuidString)
+ update.remoteHandle = CXHandle(type: .generic, value: call.sessionId)
update.hasVideo = false
disableUnsupportedFeatures(callUpdate: update)
diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift
index 3987ed35c..7f3b98ef7 100644
--- a/Session/Notifications/PushRegistrationManager.swift
+++ b/Session/Notifications/PushRegistrationManager.swift
@@ -346,6 +346,8 @@ public enum PushRegistrationError: Error {
call.reportIncomingCallIfNeeded { error in
if let error = error {
SNLog("[Calls] Failed to report incoming call to CallKit due to error: \(error)")
+ } else {
+ SNLog("[Calls] Succeeded to report incoming call to CallKit")
}
}
}
diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+Calls.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+Calls.swift
index 127ea94ac..7249ce74f 100644
--- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+Calls.swift
+++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+Calls.swift
@@ -109,6 +109,7 @@ extension MessageReceiver {
// Ignore pre offer message after the same call instance has been generated
if let currentCall: CurrentCallProtocol = callManager.currentCall, currentCall.uuid == message.uuid {
+ SNLog("[MessageReceiver+Calls] Ignoring pre-offer message for call[\(currentCall.uuid)] instance because it is already active.")
return
}
From 5fb9a6621db5bea4b64696a4a57fbe1e5450a4c7 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Fri, 29 Nov 2024 17:21:35 +1100
Subject: [PATCH 02/13] add more logs
---
Session.xcodeproj/project.pbxproj | 4 +-
.../Settings.bundle/ThirdPartyLicenses.plist | 82 +++++++++++++++++++
.../PushRegistrationManager.swift | 71 ++++++++--------
3 files changed, 122 insertions(+), 35 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index ea30ead1a..6fafaac47 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7778,7 +7778,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 496;
+ CURRENT_PROJECT_VERSION = 498;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -7849,7 +7849,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 496;
+ CURRENT_PROJECT_VERSION = 498;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/Session/Meta/Settings.bundle/ThirdPartyLicenses.plist b/Session/Meta/Settings.bundle/ThirdPartyLicenses.plist
index 1e94962d9..6ca29b954 100644
--- a/Session/Meta/Settings.bundle/ThirdPartyLicenses.plist
+++ b/Session/Meta/Settings.bundle/ThirdPartyLicenses.plist
@@ -985,6 +985,88 @@ SOFTWARE.
License
The MIT License (MIT)
+Copyright (c) 2016 swiftlyfalling (https://github.com/swiftlyfalling)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+ Title
+ session-grdb-swift
+
+
+ License
+ The author disclaims copyright to this source code. In place of
+a legal notice, here is a blessing:
+
+ * May you do good and not evil.
+ * May you find forgiveness for yourself and forgive others.
+ * May you share freely, never taking more than you give.
+
+ Title
+ session-grdb-swift
+
+
+ License
+ /*
+** LICENSE for the sqlite3 WebAssembly/JavaScript APIs.
+**
+** This bundle (typically released as sqlite3.js or sqlite3.mjs)
+** is an amalgamation of JavaScript source code from two projects:
+**
+** 1) https://emscripten.org: the Emscripten "glue code" is covered by
+** the terms of the MIT license and University of Illinois/NCSA
+** Open Source License, as described at:
+**
+** https://emscripten.org/docs/introducing_emscripten/emscripten_license.html
+**
+** 2) https://sqlite.org: all code and documentation labeled as being
+** from this source are released under the same terms as the sqlite3
+** C library:
+**
+** 2022-10-16
+**
+** The author disclaims copyright to this source code. In place of a
+** legal notice, here is a blessing:
+**
+** * May you do good and not evil.
+** * May you find forgiveness for yourself and forgive others.
+** * May you share freely, never taking more than you give.
+*/
+
+ Title
+ session-grdb-swift
+
+
+ License
+ The author disclaims copyright to this source code. In place of
+a legal notice, here is a blessing:
+
+ May you do good and not evil.
+ May you find forgiveness for yourself and forgive others.
+ May you share freely, never taking more than you give.
+
+ Title
+ session-grdb-swift
+
+
+ License
+ The MIT License (MIT)
+
Copyright (c) 2015 ibireme <ibireme@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift
index 7f3b98ef7..9b292d5f7 100644
--- a/Session/Notifications/PushRegistrationManager.swift
+++ b/Session/Notifications/PushRegistrationManager.swift
@@ -297,40 +297,45 @@ public enum PushRegistrationError: Error {
LibSession.resumeNetworkAccess()
let maybeCall: SessionCall? = Storage.shared.write { db in
- let messageInfo: CallMessage.MessageInfo = CallMessage.MessageInfo(
- state: (caller == getUserHexEncodedPublicKey(db) ?
- .outgoing :
- .incoming
- )
- )
-
- let messageInfoString: String? = {
- if let messageInfoData: Data = try? JSONEncoder().encode(messageInfo) {
- return String(data: messageInfoData, encoding: .utf8)
- } else {
- return "callsIncoming"
- .put(key: "name", value: caller)
- .localized()
- }
- }()
-
- let call: SessionCall = SessionCall(db, for: caller, uuid: uuid, mode: .answer)
- let thread: SessionThread = try SessionThread
- .fetchOrCreate(db, id: caller, variant: .contact, shouldBeVisible: nil)
-
- let interaction: Interaction = try Interaction(
- messageUuid: uuid,
- threadId: thread.id,
- threadVariant: thread.variant,
- authorId: caller,
- variant: .infoCall,
- body: messageInfoString,
- timestampMs: timestampMs
- )
- .withDisappearingMessagesConfiguration(db, threadVariant: thread.variant)
- .inserted(db)
+ var call: SessionCall? = nil
- call.callInteractionId = interaction.id
+ do {
+ let messageInfo: CallMessage.MessageInfo = CallMessage.MessageInfo(state: .incoming)
+ SNLog("[Calls] messageInfo done")
+
+ let messageInfoString: String? = {
+ if let messageInfoData: Data = try? JSONEncoder().encode(messageInfo) {
+ return String(data: messageInfoData, encoding: .utf8)
+ } else {
+ return "callsIncoming"
+ .put(key: "name", value: caller)
+ .localized()
+ }
+ }()
+ SNLog("[Calls] messageInfoString done: \(messageInfoString ?? "nil")")
+
+ call = SessionCall(db, for: caller, uuid: uuid, mode: .answer)
+ SNLog("[Calls] call instance done")
+ let thread: SessionThread = try SessionThread.fetchOrCreate(db, id: caller, variant: .contact, shouldBeVisible: nil)
+ SNLog("[Calls] thread got")
+
+ let interaction: Interaction = try Interaction(
+ messageUuid: uuid,
+ threadId: thread.id,
+ threadVariant: thread.variant,
+ authorId: caller,
+ variant: .infoCall,
+ body: messageInfoString,
+ timestampMs: timestampMs
+ )
+ .withDisappearingMessagesConfiguration(db, threadVariant: thread.variant)
+ .inserted(db)
+ SNLog("[Calls] control message inserted")
+
+ call?.callInteractionId = interaction.id
+ } catch {
+ SNLog("[Calls] Failed to creat call due to error: \(error)")
+ }
return call
}
From 780e262e52f8e94411bb13cc26224a3111c38109 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Mon, 2 Dec 2024 10:37:31 +1100
Subject: [PATCH 03/13] fix CallKit crash
---
Session.xcodeproj/project.pbxproj | 4 +-
Session/Home/HomeVC.swift | 1 +
.../PushRegistrationManager.swift | 48 +++++++------------
3 files changed, 21 insertions(+), 32 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index 6fafaac47..209af1863 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7778,7 +7778,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 498;
+ CURRENT_PROJECT_VERSION = 500;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -7849,7 +7849,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 498;
+ CURRENT_PROJECT_VERSION = 500;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift
index f9e5e732e..cc6a99633 100644
--- a/Session/Home/HomeVC.swift
+++ b/Session/Home/HomeVC.swift
@@ -354,6 +354,7 @@ final class HomeVC: BaseVC, LibSessionRespondingViewController, UITableViewDataS
// Start polling if needed (i.e. if the user just created or restored their Session ID)
if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate {
+ SNLog("[HomeVC]: Starting pollers...")
appDelegate.startPollersIfNeeded()
}
diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift
index 9b292d5f7..d1ed6c10d 100644
--- a/Session/Notifications/PushRegistrationManager.swift
+++ b/Session/Notifications/PushRegistrationManager.swift
@@ -300,39 +300,27 @@ public enum PushRegistrationError: Error {
var call: SessionCall? = nil
do {
- let messageInfo: CallMessage.MessageInfo = CallMessage.MessageInfo(state: .incoming)
- SNLog("[Calls] messageInfo done")
-
- let messageInfoString: String? = {
- if let messageInfoData: Data = try? JSONEncoder().encode(messageInfo) {
- return String(data: messageInfoData, encoding: .utf8)
- } else {
- return "callsIncoming"
- .put(key: "name", value: caller)
- .localized()
- }
- }()
- SNLog("[Calls] messageInfoString done: \(messageInfoString ?? "nil")")
+ call = SessionCall(
+ db,
+ for: caller,
+ uuid: uuid,
+ mode: .answer
+ )
- call = SessionCall(db, for: caller, uuid: uuid, mode: .answer)
- SNLog("[Calls] call instance done")
- let thread: SessionThread = try SessionThread.fetchOrCreate(db, id: caller, variant: .contact, shouldBeVisible: nil)
- SNLog("[Calls] thread got")
+ let thread: SessionThread = try SessionThread
+ .fetchOrCreate(
+ db,
+ id: caller,
+ variant: .contact,
+ shouldBeVisible: nil
+ )
- let interaction: Interaction = try Interaction(
- messageUuid: uuid,
- threadId: thread.id,
- threadVariant: thread.variant,
- authorId: caller,
- variant: .infoCall,
- body: messageInfoString,
- timestampMs: timestampMs
- )
- .withDisappearingMessagesConfiguration(db, threadVariant: thread.variant)
- .inserted(db)
- SNLog("[Calls] control message inserted")
+ let interaction: Interaction? = try Interaction
+ .filter(Interaction.Columns.threadId == thread.id)
+ .filter(Interaction.Columns.messageUuid == uuid)
+ .fetchOne(db)
- call?.callInteractionId = interaction.id
+ call?.callInteractionId = interaction?.id
} catch {
SNLog("[Calls] Failed to creat call due to error: \(error)")
}
From fc4778e79fa7775fe9b53e21bd5f8db88603e0bf Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Mon, 2 Dec 2024 11:09:52 +1100
Subject: [PATCH 04/13] don't start other pollers when app is activated in
backgroud
---
Session/Home/HomeVC.swift | 2 +-
Session/Notifications/PushRegistrationManager.swift | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift
index cc6a99633..554d51218 100644
--- a/Session/Home/HomeVC.swift
+++ b/Session/Home/HomeVC.swift
@@ -353,7 +353,7 @@ final class HomeVC: BaseVC, LibSessionRespondingViewController, UITableViewDataS
)
// Start polling if needed (i.e. if the user just created or restored their Session ID)
- if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate {
+ if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate, !Singleton.appContext.isInBackground {
SNLog("[HomeVC]: Starting pollers...")
appDelegate.startPollersIfNeeded()
}
diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift
index d1ed6c10d..6358fef63 100644
--- a/Session/Notifications/PushRegistrationManager.swift
+++ b/Session/Notifications/PushRegistrationManager.swift
@@ -284,7 +284,8 @@ public enum PushRegistrationError: Error {
guard
let uuid: String = payload["uuid"] as? String,
let caller: String = payload["caller"] as? String,
- let timestampMs: Int64 = payload["timestamp"] as? Int64
+ let timestampMs: UInt64 = payload["timestamp"] as? UInt64,
+ TimestampUtils.isWithinOneMinute(timestampMs: timestampMs)
else {
SessionCallManager.reportFakeCall(info: "Missing payload data") // stringlint:ignore
return
From bf5db2ab93b5d0e33e5e9ddb6b075ef3be4ab777 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Mon, 2 Dec 2024 13:38:21 +1100
Subject: [PATCH 05/13] fix an issue where job runner is not activated when
answering calls from CallKit
---
Session/Notifications/PushRegistrationManager.swift | 2 ++
SessionUtilitiesKit/JobRunner/JobRunner.swift | 1 +
2 files changed, 3 insertions(+)
diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift
index 6358fef63..c14a2013b 100644
--- a/Session/Notifications/PushRegistrationManager.swift
+++ b/Session/Notifications/PushRegistrationManager.swift
@@ -334,6 +334,8 @@ public enum PushRegistrationError: Error {
return
}
+ 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)
diff --git a/SessionUtilitiesKit/JobRunner/JobRunner.swift b/SessionUtilitiesKit/JobRunner/JobRunner.swift
index 7cefce9f8..63ae4c5b5 100644
--- a/SessionUtilitiesKit/JobRunner/JobRunner.swift
+++ b/SessionUtilitiesKit/JobRunner/JobRunner.swift
@@ -1901,6 +1901,7 @@ public extension JobRunner {
}
static func appDidBecomeActive(using dependencies: Dependencies = Dependencies()) {
+ SNLog("[JobRunner] appDidBecomeActive")
instance.appDidBecomeActive(using: dependencies)
}
From 58707da75ed3b755cb5a640d146d41a65a12ed7d Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Mon, 2 Dec 2024 15:11:13 +1100
Subject: [PATCH 06/13] add more logs
---
Session.xcodeproj/project.pbxproj | 4 ++--
Session/Calls/Call Management/SessionCallManager.swift | 1 +
Session/Home/HomeVC.swift | 4 ++--
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index 209af1863..fd6ec0b96 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7778,7 +7778,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 500;
+ CURRENT_PROJECT_VERSION = 502;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -7849,7 +7849,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 500;
+ CURRENT_PROJECT_VERSION = 502;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift
index 45427383e..f7c710a2b 100644
--- a/Session/Calls/Call Management/SessionCallManager.swift
+++ b/Session/Calls/Call Management/SessionCallManager.swift
@@ -140,6 +140,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
}
func handleCallEnded() {
+ SNLog("[Calls] Call ended.")
WebRTCSession.current = nil
UserDefaults.sharedLokiProject?[.isCallOngoing] = false
UserDefaults.sharedLokiProject?[.lastCallPreOffer] = nil
diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift
index 554d51218..ad34563e6 100644
--- a/Session/Home/HomeVC.swift
+++ b/Session/Home/HomeVC.swift
@@ -353,8 +353,8 @@ final class HomeVC: BaseVC, LibSessionRespondingViewController, UITableViewDataS
)
// Start polling if needed (i.e. if the user just created or restored their Session ID)
- if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate, !Singleton.appContext.isInBackground {
- SNLog("[HomeVC]: Starting pollers...")
+ if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate, Singleton.appContext.isInBackground == false {
+ SNLog("[HomeVC]: Starting pollers... \(Singleton.appContext.reportedApplicationState)")
appDelegate.startPollersIfNeeded()
}
From 1dddedf3eba50639100724867448c750bdddaf27 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Mon, 2 Dec 2024 15:42:55 +1100
Subject: [PATCH 07/13] add logs and fix a case when the call is going with
CallKit but the app state is not in background
---
Session.xcodeproj/project.pbxproj | 4 ++--
Session/Calls/Call Management/SessionCallManager.swift | 1 +
Session/Home/HomeVC.swift | 2 +-
SessionUtilitiesKit/General/AppContext.swift | 4 +++-
4 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index fd6ec0b96..50cfb2fdb 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7778,7 +7778,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 502;
+ CURRENT_PROJECT_VERSION = 503;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -7849,7 +7849,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 502;
+ CURRENT_PROJECT_VERSION = 503;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift
index f7c710a2b..045e9eb4c 100644
--- a/Session/Calls/Call Management/SessionCallManager.swift
+++ b/Session/Calls/Call Management/SessionCallManager.swift
@@ -199,6 +199,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
}
public static func suspendDatabaseIfCallEndedInBackground() {
+ SNLog("[Calls] suspendDatabaseIfCallEndedInBackground.")
if Singleton.hasAppContext && Singleton.appContext.isInBackground {
// FIXME: Initialise the `SessionCallManager` with a dependencies instance
let dependencies: Dependencies = Dependencies()
diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift
index ad34563e6..600200e64 100644
--- a/Session/Home/HomeVC.swift
+++ b/Session/Home/HomeVC.swift
@@ -354,7 +354,7 @@ final class HomeVC: BaseVC, LibSessionRespondingViewController, UITableViewDataS
// Start polling if needed (i.e. if the user just created or restored their Session ID)
if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate, Singleton.appContext.isInBackground == false {
- SNLog("[HomeVC]: Starting pollers... \(Singleton.appContext.reportedApplicationState)")
+ SNLog("[HomeVC]: Starting pollers...")
appDelegate.startPollersIfNeeded()
}
diff --git a/SessionUtilitiesKit/General/AppContext.swift b/SessionUtilitiesKit/General/AppContext.swift
index 423e8f5de..6e0bb9f46 100644
--- a/SessionUtilitiesKit/General/AppContext.swift
+++ b/SessionUtilitiesKit/General/AppContext.swift
@@ -46,7 +46,9 @@ public extension AppContext {
var frontmostViewController: UIViewController? { nil }
var backgroundTimeRemaining: TimeInterval { 0 }
- var isInBackground: Bool { reportedApplicationState == .background }
+ // Note: .inactive is a strange state, if the app is activated by VOIP and CallKit is up in the front,
+ // the app will report .inactive state
+ var isInBackground: Bool { reportedApplicationState == .background || reportedApplicationState == .inactive }
var isAppForegroundAndActive: Bool { reportedApplicationState == .active }
// MARK: - Paths
From 8f10f43494dcdd7c6e09d9c1f5a61d8a7dc0a6dc Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Mon, 2 Dec 2024 16:43:18 +1100
Subject: [PATCH 08/13] further fix on app state issues
---
Session.xcodeproj/project.pbxproj | 4 ++--
Session/Calls/Call Management/SessionCallManager.swift | 2 +-
Session/Home/HomeVC.swift | 3 +--
SessionUtilitiesKit/General/AppContext.swift | 6 +++---
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index 50cfb2fdb..6bb171e14 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7778,7 +7778,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 503;
+ CURRENT_PROJECT_VERSION = 504;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -7849,7 +7849,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 503;
+ CURRENT_PROJECT_VERSION = 504;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift
index 045e9eb4c..602536c3b 100644
--- a/Session/Calls/Call Management/SessionCallManager.swift
+++ b/Session/Calls/Call Management/SessionCallManager.swift
@@ -145,7 +145,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
UserDefaults.sharedLokiProject?[.isCallOngoing] = false
UserDefaults.sharedLokiProject?[.lastCallPreOffer] = nil
- if Singleton.hasAppContext && Singleton.appContext.isInBackground {
+ if Singleton.hasAppContext && Singleton.appContext.isNotInForeground {
(UIApplication.shared.delegate as? AppDelegate)?.stopPollers()
Log.flush()
}
diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift
index 600200e64..5b609d185 100644
--- a/Session/Home/HomeVC.swift
+++ b/Session/Home/HomeVC.swift
@@ -353,8 +353,7 @@ final class HomeVC: BaseVC, LibSessionRespondingViewController, UITableViewDataS
)
// Start polling if needed (i.e. if the user just created or restored their Session ID)
- if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate, Singleton.appContext.isInBackground == false {
- SNLog("[HomeVC]: Starting pollers...")
+ if Identity.userExists(), let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate, !Singleton.appContext.isNotInForeground {
appDelegate.startPollersIfNeeded()
}
diff --git a/SessionUtilitiesKit/General/AppContext.swift b/SessionUtilitiesKit/General/AppContext.swift
index 6e0bb9f46..35dcb7e29 100644
--- a/SessionUtilitiesKit/General/AppContext.swift
+++ b/SessionUtilitiesKit/General/AppContext.swift
@@ -46,9 +46,9 @@ public extension AppContext {
var frontmostViewController: UIViewController? { nil }
var backgroundTimeRemaining: TimeInterval { 0 }
- // Note: .inactive is a strange state, if the app is activated by VOIP and CallKit is up in the front,
- // the app will report .inactive state
- var isInBackground: Bool { reportedApplicationState == .background || reportedApplicationState == .inactive }
+ // Note: CallKit will make the app state as .inactive
+ var isInBackground: Bool { reportedApplicationState == .background }
+ var isNotInForeground: Bool { reportedApplicationState != .active }
var isAppForegroundAndActive: Bool { reportedApplicationState == .active }
// MARK: - Paths
From f153fb6cf5353235ebb991f6d3781bbb62be02e0 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Wed, 4 Dec 2024 15:14:05 +1100
Subject: [PATCH 09/13] add logic to prevent duplicated message request
response being inserted into database
---
.../MessageReceiver+MessageRequests.swift | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+MessageRequests.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+MessageRequests.swift
index c9d240fbf..20819912f 100644
--- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+MessageRequests.swift
+++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+MessageRequests.swift
@@ -117,7 +117,7 @@ extension MessageReceiver {
}
// Update the `didApproveMe` state of the sender
- try updateContactApprovalStatusIfNeeded(
+ let shouldInsertControlMessage: Bool = try updateContactApprovalStatusIfNeeded(
db,
senderSessionId: senderId,
threadId: nil
@@ -138,6 +138,7 @@ extension MessageReceiver {
)
}
+ guard shouldInsertControlMessage else { return }
// Notify the user of their approval (Note: This will always appear in the un-blinded thread)
//
// Note: We want to do this last as it'll mean the un-blinded thread gets updated and the
@@ -156,11 +157,11 @@ extension MessageReceiver {
).inserted(db)
}
- internal static func updateContactApprovalStatusIfNeeded(
+ @discardableResult internal static func updateContactApprovalStatusIfNeeded(
_ db: Database,
senderSessionId: String,
threadId: String?
- ) throws {
+ ) throws -> Bool {
let userPublicKey: String = getUserHexEncodedPublicKey(db)
// If the sender of the message was the current user
@@ -171,13 +172,13 @@ extension MessageReceiver {
let threadId: String = threadId,
let thread: SessionThread = try? SessionThread.fetchOne(db, id: threadId),
!thread.isNoteToSelf(db)
- else { return }
+ else { return true }
// Sending a message to someone flags them as approved so create the contact record if
// it doesn't exist
let contact: Contact = Contact.fetchOrCreate(db, id: threadId)
- guard !contact.isApproved else { return }
+ guard !contact.isApproved else { return false }
try? contact.save(db)
_ = try? Contact
@@ -189,12 +190,14 @@ extension MessageReceiver {
// someone without approving them)
let contact: Contact = Contact.fetchOrCreate(db, id: senderSessionId)
- guard !contact.didApproveMe else { return }
+ guard !contact.didApproveMe else { return false }
try? contact.save(db)
_ = try? Contact
.filter(id: senderSessionId)
.updateAllAndConfig(db, Contact.Columns.didApproveMe.set(to: true))
}
+
+ return true
}
}
From 25ffe98912dd814097b560ba99510e0980d25dc2 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Wed, 4 Dec 2024 16:50:13 +1100
Subject: [PATCH 10/13] fix an issue when app is in background state, call
messages are not handled properly
---
Session.xcodeproj/project.pbxproj | 4 ++--
SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj
index 6bb171e14..45a8cde16 100644
--- a/Session.xcodeproj/project.pbxproj
+++ b/Session.xcodeproj/project.pbxproj
@@ -7778,7 +7778,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 504;
+ CURRENT_PROJECT_VERSION = 505;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -7849,7 +7849,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 504;
+ CURRENT_PROJECT_VERSION = 505;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift
index 1f11a1457..dd6ef8a7b 100644
--- a/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift
+++ b/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift
@@ -413,7 +413,9 @@ public class Poller {
job: job,
canStartJob: (
!forceSynchronousProcessing &&
- (Singleton.hasAppContext && !Singleton.appContext.isInBackground)
+ (Singleton.hasAppContext && !Singleton.appContext.isInBackground) ||
+ // FIXME: Better seperate the call messages handling, since we need to handle them all the time
+ SessionEnvironment.shared?.callManager.wrappedValue?.currentCall != nil
),
using: dependencies
)
From 2faad168ef80f7d9a52a15bf79e10b2db90cae4f Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Wed, 4 Dec 2024 16:51:41 +1100
Subject: [PATCH 11/13] Potentially fix a keyboard issue for calls
---
.../Call Management/SessionCallManager.swift | 3 +--
Session/Calls/CallVC.swift | 7 +++--
.../ConversationVC+Interaction.swift | 26 ++++++++++++++-----
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift
index 602536c3b..1d240f45b 100644
--- a/Session/Calls/Call Management/SessionCallManager.swift
+++ b/Session/Calls/Call Management/SessionCallManager.swift
@@ -240,8 +240,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
{
let callVC = CallVC(for: call)
callVC.conversationVC = conversationVC
- conversationVC.inputAccessoryView?.isHidden = true
- conversationVC.inputAccessoryView?.alpha = 0
+ conversationVC.hideInputAccessoryView()
presentingVC.present(callVC, animated: true, completion: nil)
}
else if !Preferences.isCallKitSupported {
diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift
index b6b352767..86d3de516 100644
--- a/Session/Calls/CallVC.swift
+++ b/Session/Calls/CallVC.swift
@@ -600,8 +600,11 @@ final class CallVC: UIViewController, VideoPreviewDelegate {
}
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { [weak self] _ in
- self?.conversationVC?.showInputAccessoryView()
- self?.presentingViewController?.dismiss(animated: true, completion: nil)
+ DispatchQueue.main.async {
+ self?.presentingViewController?.dismiss(animated: true, completion: {
+ self?.conversationVC?.showInputAccessoryView()
+ })
+ }
}
}
diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift
index ba1669fcb..e0bb1d24d 100644
--- a/Session/Conversations/ConversationVC+Interaction.swift
+++ b/Session/Conversations/ConversationVC+Interaction.swift
@@ -791,17 +791,29 @@ extension ConversationVC:
}
func hideInputAccessoryView() {
- DispatchQueue.main.async {
- self.inputAccessoryView?.isHidden = true
- self.inputAccessoryView?.alpha = 0
+ guard Thread.isMainThread else {
+ DispatchQueue.main.async {
+ self.hideInputAccessoryView()
+ }
+ return
}
+ self.inputAccessoryView?.isHidden = true
+ self.inputAccessoryView?.alpha = 0
}
func showInputAccessoryView() {
- UIView.animate(withDuration: 0.25, animations: {
- self.inputAccessoryView?.isHidden = false
- self.inputAccessoryView?.alpha = 1
- })
+ guard Thread.isMainThread else {
+ DispatchQueue.main.async {
+ self.showInputAccessoryView()
+ }
+ return
+ }
+ self.inputAccessoryView?.isHidden = false
+ self.inputAccessoryView?.alpha = 1
+// UIView.animate(withDuration: 0.25, animations: {
+// self.inputAccessoryView?.isHidden = false
+// self.inputAccessoryView?.alpha = 1
+// })
}
// MARK: MessageCellDelegate
From 12d499a5e576a90f2262167cab0c3531a7127961 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Thu, 5 Dec 2024 09:37:40 +1100
Subject: [PATCH 12/13] clean up
---
Session/Notifications/PushRegistrationManager.swift | 2 +-
SessionUtilitiesKit/JobRunner/JobRunner.swift | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift
index c14a2013b..752bdfeec 100644
--- a/Session/Notifications/PushRegistrationManager.swift
+++ b/Session/Notifications/PushRegistrationManager.swift
@@ -323,7 +323,7 @@ public enum PushRegistrationError: Error {
call?.callInteractionId = interaction?.id
} catch {
- SNLog("[Calls] Failed to creat call due to error: \(error)")
+ SNLog("[Calls] Failed to create call due to error: \(error)")
}
return call
diff --git a/SessionUtilitiesKit/JobRunner/JobRunner.swift b/SessionUtilitiesKit/JobRunner/JobRunner.swift
index 63ae4c5b5..7cefce9f8 100644
--- a/SessionUtilitiesKit/JobRunner/JobRunner.swift
+++ b/SessionUtilitiesKit/JobRunner/JobRunner.swift
@@ -1901,7 +1901,6 @@ public extension JobRunner {
}
static func appDidBecomeActive(using dependencies: Dependencies = Dependencies()) {
- SNLog("[JobRunner] appDidBecomeActive")
instance.appDidBecomeActive(using: dependencies)
}
From b37e6a03db29c52a2106d644f1e2a976df531486 Mon Sep 17 00:00:00 2001
From: Ryan ZHAO <>
Date: Thu, 5 Dec 2024 15:02:48 +1100
Subject: [PATCH 13/13] fix a keyboard issue for calls
---
Session/Calls/CallVC.swift | 12 ++++++++----
.../Conversations/ConversationVC+Interaction.swift | 10 ++++------
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift
index 86d3de516..7ebcafae0 100644
--- a/Session/Calls/CallVC.swift
+++ b/Session/Calls/CallVC.swift
@@ -601,7 +601,7 @@ final class CallVC: UIViewController, VideoPreviewDelegate {
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { [weak self] _ in
DispatchQueue.main.async {
- self?.presentingViewController?.dismiss(animated: true, completion: {
+ self?.dismiss(animated: true, completion: {
self?.conversationVC?.showInputAccessoryView()
})
}
@@ -626,9 +626,13 @@ final class CallVC: UIViewController, VideoPreviewDelegate {
AppEnvironment.shared.callManager.reportCurrentCallEnded(reason: nil)
}
- DispatchQueue.main.async {
- self?.conversationVC?.showInputAccessoryView()
- self?.presentingViewController?.dismiss(animated: true, completion: nil)
+ Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { [weak self] _ in
+ DispatchQueue.main.async {
+ self?.dismiss(animated: true, completion: {
+ self?.conversationVC?.becomeFirstResponder()
+ self?.conversationVC?.showInputAccessoryView()
+ })
+ }
}
}
}
diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift
index e0bb1d24d..248c51934 100644
--- a/Session/Conversations/ConversationVC+Interaction.swift
+++ b/Session/Conversations/ConversationVC+Interaction.swift
@@ -808,12 +808,10 @@ extension ConversationVC:
}
return
}
- self.inputAccessoryView?.isHidden = false
- self.inputAccessoryView?.alpha = 1
-// UIView.animate(withDuration: 0.25, animations: {
-// self.inputAccessoryView?.isHidden = false
-// self.inputAccessoryView?.alpha = 1
-// })
+ UIView.animate(withDuration: 0.25, animations: {
+ self.inputAccessoryView?.isHidden = false
+ self.inputAccessoryView?.alpha = 1
+ })
}
// MARK: MessageCellDelegate