From e72c6d4cbd6bc2a5563d805707645ff514f99ae8 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 28 May 2021 09:09:56 +1000 Subject: [PATCH 1/6] Mark .noThread error as non-retryable --- SessionMessagingKit/Sending & Receiving/MessageReceiver.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index 8e6e53bca..4a9e0451d 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -16,13 +16,13 @@ public enum MessageReceiver { case noThread case selfSend case decryptionFailed - // Shared sender keys case invalidGroupPublicKey case noGroupKeyPair public var isRetryable: Bool { switch self { - case .duplicateMessage, .invalidMessage, .unknownMessage, .unknownEnvelopeType, .invalidSignature, .noData, .senderBlocked, .selfSend: return false + case .duplicateMessage, .invalidMessage, .unknownMessage, .unknownEnvelopeType, + .invalidSignature, .noData, .senderBlocked, .noThread, .selfSend, .decryptionFailed: return false default: return true } } From ff1d2d2f2839df12de8f20f3aa5697d218b87613 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 28 May 2021 09:24:03 +1000 Subject: [PATCH 2/6] Remove (seemingly) unnecessary hack --- SessionMessagingKit/Database/Storage+Messaging.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/SessionMessagingKit/Database/Storage+Messaging.swift b/SessionMessagingKit/Database/Storage+Messaging.swift index 8401b8731..21e8d40e5 100644 --- a/SessionMessagingKit/Database/Storage+Messaging.swift +++ b/SessionMessagingKit/Database/Storage+Messaging.swift @@ -47,7 +47,6 @@ extension Storage { attachment.albumMessageId = tsMessage.uniqueId! attachment.save(with: transaction) } - DispatchQueue.main.async { tsMessage.touch() } // FIXME: Hack for a thread updating issue return tsMessage.uniqueId! } From bf9d86021463d3e04b4f356d2620b9503c0bd335 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 28 May 2021 09:47:05 +1000 Subject: [PATCH 3/6] Batch thread updates --- Session.xcodeproj/project.pbxproj | 4 +++ .../MessageReceiver+Handling.swift | 4 +-- .../Utilities/ThreadUpdateBatcher.swift | 31 +++++++++++++++++++ SessionUtilitiesKit/General/General.swift | 7 +++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index f0fa0524f..c9e2bf489 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -509,6 +509,7 @@ C3548F0824456AB6009433A8 /* UIView+Wrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3548F0724456AB6009433A8 /* UIView+Wrapping.swift */; }; C354E75A23FE2A7600CE22E3 /* BaseVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C354E75923FE2A7600CE22E3 /* BaseVC.swift */; }; C35D0DB525AE5F1200B6BF49 /* UIEdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35D0DB425AE5F1200B6BF49 /* UIEdgeInsets.swift */; }; + C35D76DB26606304009AA5FB /* ThreadUpdateBatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35D76DA26606303009AA5FB /* ThreadUpdateBatcher.swift */; }; C35E8AAE2485E51D00ACB629 /* IP2Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35E8AAD2485E51D00ACB629 /* IP2Country.swift */; }; C374EEE225DA26740073A857 /* LinkPreviewModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C374EEE125DA26740073A857 /* LinkPreviewModal.swift */; }; C374EEEB25DA3CA70073A857 /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C374EEEA25DA3CA70073A857 /* ConversationTitleView.swift */; }; @@ -1487,6 +1488,7 @@ C3548F0724456AB6009433A8 /* UIView+Wrapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Wrapping.swift"; sourceTree = ""; }; C354E75923FE2A7600CE22E3 /* BaseVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseVC.swift; sourceTree = ""; }; C35D0DB425AE5F1200B6BF49 /* UIEdgeInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIEdgeInsets.swift; sourceTree = ""; }; + C35D76DA26606303009AA5FB /* ThreadUpdateBatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadUpdateBatcher.swift; sourceTree = ""; }; C35E8AA22485C72300ACB629 /* SwiftCSV.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftCSV.framework; path = ThirdParty/Carthage/Build/iOS/SwiftCSV.framework; sourceTree = ""; }; C35E8AAD2485E51D00ACB629 /* IP2Country.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IP2Country.swift; sourceTree = ""; }; C374EEE125DA26740073A857 /* LinkPreviewModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewModal.swift; sourceTree = ""; }; @@ -3145,6 +3147,7 @@ C33FDB32255A580A00E217F9 /* SSKIncrementingIdFinder.swift */, C3A3A170256E1D25004D228D /* SSKReachabilityManager.swift */, C3ECBF7A257056B700EA7FCE /* Threading.swift */, + C35D76DA26606303009AA5FB /* ThreadUpdateBatcher.swift */, C33FDB5F255A580E00E217F9 /* YapDatabaseConnection+OWS.h */, C33FDB43255A580C00E217F9 /* YapDatabaseConnection+OWS.m */, C33FDA88255A57FD00E217F9 /* YapDatabaseTransaction+OWS.h */, @@ -4680,6 +4683,7 @@ B8856CEE256F1054001CE70E /* OWSAudioPlayer.m in Sources */, C32C5EDC256DF501003C73A2 /* YapDatabaseConnection+OWS.m in Sources */, C3BBE0762554CDA60050F1E3 /* Configuration.swift in Sources */, + C35D76DB26606304009AA5FB /* ThreadUpdateBatcher.swift in Sources */, B8B32033258B235D0020074B /* Storage+Contacts.swift in Sources */, B8856D69256F141F001CE70E /* OWSWindowManager.m in Sources */, C3D9E3BE25676AD70040E4F3 /* TSAttachmentPointer.m in Sources */, diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index 177b60ba9..0d0eb6a23 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -25,9 +25,7 @@ extension MessageReceiver { // Touch the thread to update the home screen preview let storage = SNMessagingKitConfiguration.shared.storage guard let threadID = storage.getOrCreateThread(for: message.sender!, groupPublicKey: message.groupPublicKey, openGroupID: openGroupID, using: transaction) else { return } - let transaction = transaction as! YapDatabaseReadWriteTransaction - guard let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) else { return } - thread.touch(with: transaction) + ThreadUpdateBatcher.shared.touch(threadID) } diff --git a/SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift b/SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift new file mode 100644 index 000000000..3eebcbda9 --- /dev/null +++ b/SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift @@ -0,0 +1,31 @@ + +final class ThreadUpdateBatcher { + private var threadIDs: Set = [] + + private lazy var timer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { [weak self] _ in self?.touch() } + + static let shared = ThreadUpdateBatcher() + + private init() { + DispatchQueue.main.async { + SessionUtilitiesKit.touch(self.timer) + } + } + + deinit { timer.invalidate() } + + func touch(_ threadID: String) { + threadIDs.insert(threadID) + } + + @objc private func touch() { + let threadIDs = self.threadIDs + self.threadIDs.removeAll() + Storage.write { transaction in + for threadID in threadIDs { + guard let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) else { return } + thread.touch(with: transaction) + } + } + } +} diff --git a/SessionUtilitiesKit/General/General.swift b/SessionUtilitiesKit/General/General.swift index 08c97811c..804149346 100644 --- a/SessionUtilitiesKit/General/General.swift +++ b/SessionUtilitiesKit/General/General.swift @@ -1,4 +1,11 @@ +/// Does nothing, but is never inlined and thus evaluating its argument will never be optimized away. +/// +/// Useful for forcing the instantiation of lazy properties like globals. +@inline(never) +public func touch(_ value: Value) { /* Do nothing */ } + + /// Returns `f(x!)` if `x != nil`, or `nil` otherwise. public func given(_ x: T?, _ f: (T) throws -> U) rethrows -> U? { return try x.map(f) } From 2730804e4a50909e593fae60c7ea1bfd1e0d414e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 28 May 2021 09:47:48 +1000 Subject: [PATCH 4/6] Update version number --- Session.xcodeproj/project.pbxproj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index c9e2bf489..249ac73da 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -5058,7 +5058,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 251; + CURRENT_PROJECT_VERSION = 252; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5079,7 +5079,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.11.3; + MARKETING_VERSION = 1.11.4; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5127,7 +5127,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 251; + CURRENT_PROJECT_VERSION = 252; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5153,7 +5153,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.11.3; + MARKETING_VERSION = 1.11.4; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5188,7 +5188,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 251; + CURRENT_PROJECT_VERSION = 252; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5207,7 +5207,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.11.3; + MARKETING_VERSION = 1.11.4; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -5258,7 +5258,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 251; + CURRENT_PROJECT_VERSION = 252; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5282,7 +5282,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.11.3; + MARKETING_VERSION = 1.11.4; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -6143,7 +6143,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 251; + CURRENT_PROJECT_VERSION = 252; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6179,7 +6179,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.11.3; + MARKETING_VERSION = 1.11.4; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -6211,7 +6211,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 251; + CURRENT_PROJECT_VERSION = 252; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6247,7 +6247,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.11.3; + MARKETING_VERSION = 1.11.4; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; From c98cfe420d09000aa07474f46702ec65f5b38b42 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 28 May 2021 09:58:33 +1000 Subject: [PATCH 5/6] Fix spacing --- SessionUtilitiesKit/General/General.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/SessionUtilitiesKit/General/General.swift b/SessionUtilitiesKit/General/General.swift index 804149346..7fb5bacdf 100644 --- a/SessionUtilitiesKit/General/General.swift +++ b/SessionUtilitiesKit/General/General.swift @@ -5,7 +5,6 @@ @inline(never) public func touch(_ value: Value) { /* Do nothing */ } - /// Returns `f(x!)` if `x != nil`, or `nil` otherwise. public func given(_ x: T?, _ f: (T) throws -> U) rethrows -> U? { return try x.map(f) } From 1b4cfdb22f7daa895ccedbeb2a10f966cf17248e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 28 May 2021 14:28:59 +1000 Subject: [PATCH 6/6] Add get Session version file server endpoint --- SessionMessagingKit/File Server/FileServerAPIV2.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SessionMessagingKit/File Server/FileServerAPIV2.swift b/SessionMessagingKit/File Server/FileServerAPIV2.swift index 9e311be00..a5b880b36 100644 --- a/SessionMessagingKit/File Server/FileServerAPIV2.swift +++ b/SessionMessagingKit/File Server/FileServerAPIV2.swift @@ -114,4 +114,12 @@ public final class FileServerAPIV2 : NSObject { return file } } + + public static func getVersion(_ platform: String) -> Promise { + let request = Request(verb: .get, endpoint: "session_version?platform=\(platform)") + return send(request, useOldServer: false).map(on: DispatchQueue.global(qos: .userInitiated)) { json in + guard let version = json["result"] as? String else { throw Error.parsingFailed } + return version + } + } }