diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 301095b54..15356b07d 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -5229,7 +5229,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 345; + CURRENT_PROJECT_VERSION = 347; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5254,7 +5254,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.9; + MARKETING_VERSION = 1.12.10; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5302,7 +5302,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 345; + CURRENT_PROJECT_VERSION = 347; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5332,7 +5332,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.9; + MARKETING_VERSION = 1.12.10; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5368,7 +5368,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 345; + CURRENT_PROJECT_VERSION = 347; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5391,7 +5391,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.9; + MARKETING_VERSION = 1.12.10; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -5442,7 +5442,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 345; + CURRENT_PROJECT_VERSION = 347; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5470,7 +5470,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.12.9; + MARKETING_VERSION = 1.12.10; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -6378,7 +6378,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 345; + CURRENT_PROJECT_VERSION = 347; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6418,7 +6418,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.12.9; + MARKETING_VERSION = 1.12.10; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -6451,7 +6451,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 345; + CURRENT_PROJECT_VERSION = 347; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6491,7 +6491,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.12.9; + MARKETING_VERSION = 1.12.10; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 540d734bd..78d0924f6 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -63,7 +63,7 @@ extension AppDelegate { let thread = TSContactThread.getOrCreateThread(withContactSessionID: message.sender!, transaction: transaction) let infoMessage = TSInfoMessage.from(message, associatedWith: thread) infoMessage.save(with: transaction) - receivedCalls.insert(message.uuid!) + receivedCalls.insert(uuid) Storage.shared.setReceivedCalls(to: receivedCalls, for: sender, using: transaction) return infoMessage } diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift index 70a3698fd..c25f6941e 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift @@ -61,7 +61,16 @@ public final class ClosedGroupPoller : NSObject { // MARK: Private API private func setUpPolling(for groupPublicKey: String) { Threading.pollerQueue.async { - self.poll(groupPublicKey).done(on: Threading.pollerQueue) { [weak self] _ in + let promises: [Promise] = { + if SnodeAPI.hardfork >= 19 && SnodeAPI.softfork >= 1 { + return [ self.poll(groupPublicKey) ] + } + if SnodeAPI.hardfork >= 19 { + return [ self.poll(groupPublicKey, defaultInbox: true), self.poll(groupPublicKey) ] + } + return [ self.poll(groupPublicKey, defaultInbox: true) ] + }() + when(resolved: promises).done(on: Threading.pollerQueue) { [weak self] _ in self?.pollRecursively(groupPublicKey) }.catch(on: Threading.pollerQueue) { [weak self] error in // The error is logged in poll(_:) @@ -87,13 +96,15 @@ public final class ClosedGroupPoller : NSObject { timers[groupPublicKey] = Timer.scheduledTimerOnMainThread(withTimeInterval: nextPollInterval, repeats: false) { [weak self] timer in timer.invalidate() Threading.pollerQueue.async { - var promises: [Promise] = [] - if SnodeAPI.hardfork <= 19, SnodeAPI.softfork == 0, let promise = self?.poll(groupPublicKey, defaultInbox: true) { - promises.append(promise) - } - if SnodeAPI.hardfork >= 19, SnodeAPI.softfork >= 0,let promise = self?.poll(groupPublicKey) { - promises.append(promise) - } + let promises: [Promise] = { + if SnodeAPI.hardfork >= 19 && SnodeAPI.softfork >= 1 { + return [ self?.poll(groupPublicKey) ].compactMap{ $0 } + } + if SnodeAPI.hardfork >= 19 { + return [ self?.poll(groupPublicKey, defaultInbox: true), self?.poll(groupPublicKey) ].compactMap{ $0 } + } + return [ self?.poll(groupPublicKey, defaultInbox: true) ].compactMap{ $0 } + }() when(resolved: promises).done(on: Threading.pollerQueue) { _ in self?.pollRecursively(groupPublicKey) }.catch(on: Threading.pollerQueue) { error in diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index db7e22d51..d1d598191 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -78,9 +78,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension guard case .preOffer = callMessage.kind else { return self.completeSilenty() } if !SSKPreferences.areCallsEnabled { if let sender = callMessage.sender, let thread = TSContactThread.fetch(for: sender, using: transaction), !thread.isMessageRequest(using: transaction) { - let infoMessage = TSInfoMessage.from(callMessage, associatedWith: thread) - infoMessage.updateCallInfoMessage(.permissionDenied, using: transaction) - SSKEnvironment.shared.notificationsManager?.notifyUser(forIncomingCall: infoMessage, in: thread, transaction: transaction) + self.insertCallInfoMessage(for: callMessage, in: thread, reason: .permissionDenied, using: transaction) } break } @@ -92,9 +90,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension message.kind = .endCall SNLog("[Calls] Sending end call message because there is an ongoing call.") MessageSender.sendNonDurably(message, in: thread, using: transaction).retainUntilComplete() - let infoMessage = TSInfoMessage.from(callMessage, associatedWith: thread) - infoMessage.updateCallInfoMessage(.missed, using: transaction) - SSKEnvironment.shared.notificationsManager?.notifyUser(forIncomingCall: infoMessage, in: thread, transaction: transaction) + self.insertCallInfoMessage(for: callMessage, in: thread, reason: .missed, using: transaction) } break } @@ -112,6 +108,18 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension } } } + + private func insertCallInfoMessage(for message: CallMessage, in thread: TSThread, reason: TSInfoMessageCallState, using transaction: YapDatabaseReadWriteTransaction) { + guard let sender = message.sender, let uuid = message.uuid else { return } + var receivedCalls = Storage.shared.getReceivedCalls(for: sender, using: transaction) + if !receivedCalls.contains(uuid) { + let infoMessage = TSInfoMessage.from(message, associatedWith: thread) + infoMessage.updateCallInfoMessage(reason, using: transaction) + SSKEnvironment.shared.notificationsManager?.notifyUser(forIncomingCall: infoMessage, in: thread, transaction: transaction) + receivedCalls.insert(uuid) + Storage.shared.setReceivedCalls(to: receivedCalls, for: sender, using: transaction) + } + } // MARK: Setup @@ -263,6 +271,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension } // MARK: Poll for open groups + private func pollForOpenGroups() -> [Promise] { var promises: [Promise] = [] let servers = Set(Storage.shared.getAllV2OpenGroups().values.map { $0.server })