From aa14ac60b1bcd0eb87ecad4b4cba7094bd8a4716 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Thu, 5 Nov 2020 12:03:24 +1100 Subject: [PATCH 01/14] retry attachments downloads failed in NSE when user goes to corresponding conversation --- .../ConversationView/ConversationViewModel.m | 12 ++++++++++++ .../Messages/Attachments/OWSAttachmentDownloads.m | 7 +++++++ .../src/Messages/Interactions/TSMessage.h | 2 ++ .../src/Messages/OWSFailedAttachmentDownloadsJob.m | 8 ++++++++ 4 files changed, 29 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m index 1b438a869..dea5b0123 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m @@ -1235,6 +1235,18 @@ static const int kYapDatabaseRangeMaxLength = 25000; OWSAssertDebug(!viewItemCache[interaction.uniqueId]); viewItemCache[interaction.uniqueId] = viewItem; [viewItems addObject:viewItem]; + TSMessage *message = (TSMessage *)viewItem.interaction; + if (message.hasAttachmentsInNSE) { + [SSKEnvironment.shared.attachmentDownloads downloadAttachmentsForMessage:message + transaction:transaction + success:^(NSArray *attachmentStreams) { + OWSLogInfo(@"Successfully redownloaded attachment in thread: %@", message.thread); + } + failure:^(NSError *error) { + OWSLogWarn(@"Failed to redownload message with error: %@", error); + }]; + } + return viewItem; }; diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m index f0471f14d..a471bf8e1 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m @@ -290,6 +290,13 @@ typedef void (^AttachmentDownloadFailure)(NSError *error); [job.attachmentPointer saveWithTransaction:transaction]; if (job.message) { + if (!CurrentAppContext().isMainApp) { + job.message.hasAttachmentsInNSE = true; + } else { + job.message.hasAttachmentsInNSE = false; + } + + [job.message saveWithTransaction:transaction]; [job.message touchWithTransaction:transaction]; } }]; diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.h b/SignalServiceKit/src/Messages/Interactions/TSMessage.h index e4085c094..d8b5af2d7 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.h @@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN // Open groups @property (nonatomic) uint64_t openGroupServerMessageID; @property (nonatomic, readonly) BOOL isOpenGroupMessage; +// Attachments in NSE +@property (nonatomic) BOOL hasAttachmentsInNSE; - (instancetype)initInteractionWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread NS_UNAVAILABLE; diff --git a/SignalServiceKit/src/Messages/OWSFailedAttachmentDownloadsJob.m b/SignalServiceKit/src/Messages/OWSFailedAttachmentDownloadsJob.m index f4d2a092d..010882650 100644 --- a/SignalServiceKit/src/Messages/OWSFailedAttachmentDownloadsJob.m +++ b/SignalServiceKit/src/Messages/OWSFailedAttachmentDownloadsJob.m @@ -3,6 +3,8 @@ // #import "OWSFailedAttachmentDownloadsJob.h" +#import "SSKEnvironment.h" +#import "OWSAttachmentDownloads.h" #import "OWSPrimaryStorage.h" #import "TSAttachmentPointer.h" #import @@ -25,6 +27,12 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i @implementation OWSFailedAttachmentDownloadsJob +- (OWSAttachmentDownloads *)attachmentDownloads +{ + return SSKEnvironment.shared.attachmentDownloads; +} + + - (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage { self = [super init]; From dcdf603a19a4d837c7bb4c82d5a6b23ac63ed153 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 10 Nov 2020 14:43:02 +1100 Subject: [PATCH 02/14] use v3/lsrpc endpoint for more compact (base64) file downloads --- SignalServiceKit/src/Loki/API/DotNetAPI.swift | 4 ++-- .../API/Onion Requests/OnionRequestAPI+Encryption.swift | 8 ++++---- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/DotNetAPI.swift b/SignalServiceKit/src/Loki/API/DotNetAPI.swift index 7fc906bfd..10ac7ce12 100644 --- a/SignalServiceKit/src/Loki/API/DotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/DotNetAPI.swift @@ -127,11 +127,11 @@ public class DotNetAPI : NSObject { return attempt(maxRetryCount: maxRetryCount, recoveringOn: SnodeAPI.workQueue) { serverPublicKeyPromise.then2 { serverPublicKey in return OnionRequestAPI.sendOnionRequest(request, to: host, using: serverPublicKey, isJSONRequired: false).map2 { json in - guard let body = json["body"] as? JSON, let data = body["data"] as? [UInt8] else { + guard let body = json["result"] as? String, let data = Data(base64Encoded: body) else { print("[Loki] Couldn't parse attachment from: \(json).") throw DotNetAPIError.parsingFailed } - return Data(data) + return data } } } diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift index 84a8da122..04ac04160 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift @@ -26,7 +26,7 @@ extension OnionRequestAPI { let plaintext = try encode(ciphertext: payloadAsData, json: [ "headers" : "" ]) let result = try EncryptionUtilities.encrypt(plaintext, using: snodeX25519PublicKey) seal.fulfill(result) - case .server(_, let serverX25519PublicKey): + case .server(_, _, let serverX25519PublicKey): let plaintext = try JSONSerialization.data(withJSONObject: payload, options: [ .fragmentsAllowed ]) let result = try EncryptionUtilities.encrypt(plaintext, using: serverX25519PublicKey) seal.fulfill(result) @@ -47,8 +47,8 @@ extension OnionRequestAPI { case .snode(let snode): guard let snodeED25519PublicKey = snode.publicKeySet?.ed25519Key else { return seal.reject(Error.snodePublicKeySetMissing) } parameters = [ "destination" : snodeED25519PublicKey ] - case .server(let host, _): - parameters = [ "host" : host, "target" : "/loki/v2/lsrpc", "method" : "POST" ] + case .server(let host, let target, _): + parameters = [ "host" : host, "target" : target, "method" : "POST" ] } parameters["ephemeral_key"] = previousEncryptionResult.ephemeralPublicKey.toHexString() let x25519PublicKey: String @@ -56,7 +56,7 @@ extension OnionRequestAPI { case .snode(let snode): guard let snodeX25519PublicKey = snode.publicKeySet?.x25519Key else { return seal.reject(Error.snodePublicKeySetMissing) } x25519PublicKey = snodeX25519PublicKey - case .server(_, let serverX25519PublicKey): + case .server(_, _, let serverX25519PublicKey): x25519PublicKey = serverX25519PublicKey } do { diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index 66432ef61..4b16a3b33 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -24,7 +24,7 @@ public enum OnionRequestAPI { // MARK: Destination internal enum Destination { case snode(Snode) - case server(host: String, x25519PublicKey: String) + case server(host: String, target: String, x25519PublicKey: String) } // MARK: Error @@ -280,7 +280,7 @@ public enum OnionRequestAPI { } /// Sends an onion request to `server`. Builds new paths as needed. - internal static func sendOnionRequest(_ request: NSURLRequest, to server: String, using x25519PublicKey: String, isJSONRequired: Bool = true) -> Promise { + internal static func sendOnionRequest(_ request: NSURLRequest, to server: String, target: String = "/loki/v3/lsrpc", using x25519PublicKey: String, isJSONRequired: Bool = true) -> Promise { var rawHeaders = request.allHTTPHeaderFields ?? [:] rawHeaders.removeValue(forKey: "User-Agent") var headers: JSON = rawHeaders.mapValues { value in @@ -323,7 +323,7 @@ public enum OnionRequestAPI { "method" : request.httpMethod!, "headers" : headers ] - let destination = Destination.server(host: host, x25519PublicKey: x25519PublicKey) + let destination = Destination.server(host: host, target: target, x25519PublicKey: x25519PublicKey) let promise = sendOnionRequest(with: payload, to: destination, isJSONRequired: isJSONRequired) promise.catch2 { error in print("[Loki] [Onion Request API] Couldn't reach server: \(url) due to error: \(error).") From 2915a51a287638d28ca25992fc5d8cc482ad850e Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 11 Nov 2020 09:41:57 +1100 Subject: [PATCH 03/14] set fileSizeORMultiplier to 2 --- SignalServiceKit/src/Loki/API/FileServerAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/FileServerAPI.swift b/SignalServiceKit/src/Loki/API/FileServerAPI.swift index 003785850..0f378806d 100644 --- a/SignalServiceKit/src/Loki/API/FileServerAPI.swift +++ b/SignalServiceKit/src/Loki/API/FileServerAPI.swift @@ -16,7 +16,7 @@ public final class FileServerAPI : DotNetAPI { /// be other parameters in the request. On average the multiplier appears to be about 1.5, so when checking whether the file will exceed the file size limit when /// uploading a file we just divide the size of the file by this number. The alternative would be to actually check the size of the HTTP request but that's only /// possible after proof of work has been calculated and the onion request encryption has happened, which takes several seconds. - public static let fileSizeORMultiplier: Double = 6 // TODO: It should be possible to set this to 1.5? + public static let fileSizeORMultiplier: Double = 2 // TODO: It should be possible to set this to 1.5? @objc public static let server = "https://file.getsession.org" @objc public static let fileStorageBucketURL = "https://file-static.lokinet.org" From 701e8444beb67031bd4e82c507925e357cae23a8 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 11 Nov 2020 15:44:11 +1100 Subject: [PATCH 04/14] fix open group avatar issue --- .../src/Loki/API/Open Groups/PublicChatAPI.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift b/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift index 1661414bc..71ff23253 100644 --- a/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift +++ b/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift @@ -388,7 +388,11 @@ public final class PublicChatAPI : DotNetAPI { if oldProfilePictureURL != info.profilePictureURL || groupModel.groupImage == nil { storage.setProfilePictureURL(info.profilePictureURL, forPublicChatWithID: publicChatID, in: transaction) if let profilePictureURL = info.profilePictureURL { - let url = server.hasSuffix("/") ? "\(server)\(profilePictureURL)" : "\(server)/\(profilePictureURL)" + var sanitizedServerURL = server + var sanitizedProfilePictureURL = profilePictureURL + while sanitizedServerURL.hasSuffix("/") { sanitizedServerURL.removeLast(1) } + while sanitizedProfilePictureURL.hasPrefix("/") { sanitizedProfilePictureURL.removeFirst(1) } + let url = "\(sanitizedServerURL)/\(sanitizedProfilePictureURL)" FileServerAPI.downloadAttachment(from: url).map2 { data in let attachmentStream = TSAttachmentStream(contentType: OWSMimeTypeImageJpeg, byteCount: UInt32(data.count), sourceFilename: nil, caption: nil, albumMessageId: nil) try attachmentStream.write(data) From e13a7d7e155c19c7fa431742b42dc8a50d829800 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Thu, 12 Nov 2020 11:18:07 +1100 Subject: [PATCH 05/14] set PN server request target as "/loki/v2/lsrpc", --- .../Push Notifications/LokiPushNotificationManager.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift b/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift index 253e63be7..2333a7970 100644 --- a/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift +++ b/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift @@ -30,7 +30,7 @@ public final class LokiPushNotificationManager : NSObject { let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] let promise: Promise = attempt(maxRetryCount: maxRetryCount, recoveringOn: DispatchQueue.global()) { - OnionRequestAPI.sendOnionRequest(request, to: server, using: pnServerPublicKey).map2 { response in + OnionRequestAPI.sendOnionRequest(request, to: server, target: "/loki/v2/lsrpc", using: pnServerPublicKey).map2 { response in guard let json = response["body"] as? JSON else { return print("[Loki] Couldn't unregister from push notifications.") } @@ -72,7 +72,7 @@ public final class LokiPushNotificationManager : NSObject { let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] let promise: Promise = attempt(maxRetryCount: maxRetryCount, recoveringOn: DispatchQueue.global()) { - OnionRequestAPI.sendOnionRequest(request, to: server, using: pnServerPublicKey).map2 { response in + OnionRequestAPI.sendOnionRequest(request, to: server, target: "/loki/v2/lsrpc", using: pnServerPublicKey).map2 { response in guard let json = response["body"] as? JSON else { return print("[Loki] Couldn't register device token.") } @@ -109,7 +109,7 @@ public final class LokiPushNotificationManager : NSObject { let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] let promise: Promise = attempt(maxRetryCount: maxRetryCount, recoveringOn: DispatchQueue.global()) { - OnionRequestAPI.sendOnionRequest(request, to: server, using: pnServerPublicKey).map2 { response in + OnionRequestAPI.sendOnionRequest(request, to: server, target: "/loki/v2/lsrpc", using: pnServerPublicKey).map2 { response in guard let json = response["body"] as? JSON else { return print("[Loki] Couldn't subscribe/unsubscribe closed group: \(closedGroupPublicKey).") } @@ -131,7 +131,7 @@ public final class LokiPushNotificationManager : NSObject { let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] let promise: Promise = attempt(maxRetryCount: maxRetryCount, recoveringOn: DispatchQueue.global()) { - OnionRequestAPI.sendOnionRequest(request, to: server, using: pnServerPublicKey).map2 { response in + OnionRequestAPI.sendOnionRequest(request, to: server, target: "/loki/v2/lsrpc", using: pnServerPublicKey).map2 { response in guard let json = response["body"] as? JSON else { return print("[Loki] Couldn't notify PN server.") } From f7b4248a22666d21cfeda7ea83821c044ad28b7e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 4 Nov 2020 15:42:57 +1100 Subject: [PATCH 06/14] Update build number --- Signal.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index fe8cc044f..408cf19c0 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4157,7 +4157,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4219,7 +4219,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4273,7 +4273,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4343,7 +4343,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4405,7 +4405,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4468,7 +4468,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4669,7 +4669,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4736,7 +4736,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 139; + CURRENT_PROJECT_VERSION = 140; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From 4b652b48b01eca4ea62a7731a9b968538b3ef6ee Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 4 Nov 2020 16:22:00 +1100 Subject: [PATCH 07/14] Update version number --- Signal.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 408cf19c0..66fffe91a 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4171,7 +4171,7 @@ INFOPLIST_FILE = SignalShareExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.share-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4238,7 +4238,7 @@ INFOPLIST_FILE = SignalShareExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.share-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4292,7 +4292,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.utilities"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -4367,7 +4367,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.utilities"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -4417,7 +4417,7 @@ INFOPLIST_FILE = LokiPushNotificationService/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.push-notification-service"; @@ -4485,7 +4485,7 @@ INFOPLIST_FILE = LokiPushNotificationService/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.push-notification-service"; @@ -4704,7 +4704,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -4771,7 +4771,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.6.5; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; From b7eeaffb3140902cf76b11f9611b0dade0d8d47a Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 6 Nov 2020 14:14:44 +1100 Subject: [PATCH 08/14] Update build number --- Signal.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 66fffe91a..aff54fd3d 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4157,7 +4157,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4219,7 +4219,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4273,7 +4273,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4343,7 +4343,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4405,7 +4405,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4468,7 +4468,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4669,7 +4669,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4736,7 +4736,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 140; + CURRENT_PROJECT_VERSION = 141; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From 5c98d55dc6645dfaa42c0eae6fffb3621d6182d6 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 12 Nov 2020 11:43:46 +1100 Subject: [PATCH 09/14] Update build number --- Signal.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index aff54fd3d..d011aa227 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4157,7 +4157,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4219,7 +4219,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4273,7 +4273,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4343,7 +4343,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4405,7 +4405,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4468,7 +4468,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4669,7 +4669,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4736,7 +4736,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 141; + CURRENT_PROJECT_VERSION = 142; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From b88bfd1da0e53ecd88cbd9eea2175a75ea76dfa0 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 13 Nov 2020 08:41:54 +1100 Subject: [PATCH 10/14] Configure SessionMessagingKit --- Session/AppDelegate+OpenGroupAPI.swift | 37 ++++ Session/Configuration.swift | 14 ++ .../Storage+SessionMessagingKit.swift | 158 ++++++++++++++++++ .../Database/Storage+SessionSnodeKit.swift | 2 +- Session/Database/Storage+Shared.swift | 10 ++ SessionMessagingKit/Configuration.swift | 2 +- .../Open Groups/OpenGroupAPI.swift | 2 +- SessionMessagingKit/Storage.swift | 10 +- Signal.xcodeproj/project.pbxproj | 8 + 9 files changed, 235 insertions(+), 8 deletions(-) create mode 100644 Session/AppDelegate+OpenGroupAPI.swift create mode 100644 Session/Database/Storage+SessionMessagingKit.swift diff --git a/Session/AppDelegate+OpenGroupAPI.swift b/Session/AppDelegate+OpenGroupAPI.swift new file mode 100644 index 000000000..669c5880e --- /dev/null +++ b/Session/AppDelegate+OpenGroupAPI.swift @@ -0,0 +1,37 @@ + +extension AppDelegate : OpenGroupAPIDelegate { + + public func updateProfileIfNeeded(for channel: UInt64, on server: String, from info: OpenGroupInfo) { + let storage = OWSPrimaryStorage.shared() + let publicChatID = "\(server).\(channel)" + Storage.writeSync { transaction in + // Update user count + storage.setUserCount(info.memberCount, forPublicChatWithID: publicChatID, in: transaction) + let groupThread = TSGroupThread.getOrCreateThread(withGroupId: publicChatID.data(using: .utf8)!, groupType: .openGroup, transaction: transaction) + // Update display name if needed + let groupModel = groupThread.groupModel + if groupModel.groupName != info.displayName { + let newGroupModel = TSGroupModel(title: info.displayName, memberIds: groupModel.groupMemberIds, image: groupModel.groupImage, groupId: groupModel.groupId, groupType: groupModel.groupType, adminIds: groupModel.groupAdminIds) + groupThread.groupModel = newGroupModel + groupThread.save(with: transaction) + } + // Download and update profile picture if needed + let oldProfilePictureURL = storage.getProfilePictureURL(forPublicChatWithID: publicChatID, in: transaction) + if oldProfilePictureURL != info.profilePictureURL || groupModel.groupImage == nil { + storage.setProfilePictureURL(info.profilePictureURL, forPublicChatWithID: publicChatID, in: transaction) + if let profilePictureURL = info.profilePictureURL { + var sanitizedServerURL = server + var sanitizedProfilePictureURL = profilePictureURL + while sanitizedServerURL.hasSuffix("/") { sanitizedServerURL.removeLast(1) } + while sanitizedProfilePictureURL.hasPrefix("/") { sanitizedProfilePictureURL.removeFirst(1) } + let url = "\(sanitizedServerURL)/\(sanitizedProfilePictureURL)" + FileServerAPI.downloadAttachment(from: url).map2 { data in + let attachmentStream = TSAttachmentStream(contentType: OWSMimeTypeImageJpeg, byteCount: UInt32(data.count), sourceFilename: nil, caption: nil, albumMessageId: nil) + try attachmentStream.write(data) + groupThread.updateAvatar(with: attachmentStream) + } + } + } + } + } +} diff --git a/Session/Configuration.swift b/Session/Configuration.swift index a30b8c684..4982d88a1 100644 --- a/Session/Configuration.swift +++ b/Session/Configuration.swift @@ -1,10 +1,24 @@ +import SessionMessagingKit import SessionProtocolKit import SessionSnodeKit @objc(SNConfiguration) final class Configuration : NSObject { + private static let pnServerURL = "https://live.apns.getsession.org" + private static let pnServerPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049" + @objc static func performMainSetup() { + SNMessagingKit.configure( + storage: Storage.shared, + signalStorage: OWSPrimaryStorage.shared(), + identityKeyStore: OWSIdentityManager.shared(), + sessionRestorationImplementation: SessionRestorationImplementation(), + certificateValidator: SMKCertificateDefaultValidator(trustRoot: OWSUDManagerImpl.trustRoot()), + openGroupAPIDelegate: UIApplication.shared.delegate as! AppDelegate, + pnServerURL: pnServerURL, + pnServerPublicKey: pnServerURL + ) SessionProtocolKit.configure(storage: Storage.shared, sharedSenderKeysDelegate: UIApplication.shared.delegate as! AppDelegate) SessionSnodeKit.configure(storage: Storage.shared) } diff --git a/Session/Database/Storage+SessionMessagingKit.swift b/Session/Database/Storage+SessionMessagingKit.swift new file mode 100644 index 000000000..66156eee6 --- /dev/null +++ b/Session/Database/Storage+SessionMessagingKit.swift @@ -0,0 +1,158 @@ +import Foundation +import PromiseKit + +extension Storage : SessionMessagingKitStorageProtocol { + + // MARK: Signal Protocol + public func getOrGenerateRegistrationID(using transaction: Any) -> UInt32 { + SSKEnvironment.shared.tsAccountManager.getOrGenerateRegistrationId(transaction as! YapDatabaseReadWriteTransaction) + } + + public func getSenderCertificate(for publicKey: String) -> SMKSenderCertificate { + let (promise, seal) = Promise.pending() + SSKEnvironment.shared.udManager.ensureSenderCertificate { senderCertificate in + seal.fulfill(senderCertificate) + } failure: { error in + // Should never fail + } + return try! promise.wait() + } + + // MARK: Shared Sender Keys + private static let closedGroupPrivateKeyCollection = "LokiClosedGroupPrivateKeyCollection" + + public func getClosedGroupPrivateKey(for publicKey: String) -> String? { + var result: String? + Storage.read { transaction in + result = transaction.object(forKey: publicKey, inCollection: Storage.closedGroupPrivateKeyCollection) as? String + } + return result + } + + internal static func setClosedGroupPrivateKey(_ privateKey: String, for publicKey: String, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).setObject(privateKey, forKey: publicKey, inCollection: Storage.closedGroupPrivateKeyCollection) + } + + internal static func removeClosedGroupPrivateKey(for publicKey: String, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).removeObject(forKey: publicKey, inCollection: Storage.closedGroupPrivateKeyCollection) + } + + func getUserClosedGroupPublicKeys() -> Set { + var result: Set = [] + Storage.read { transaction in + result = Set(transaction.allKeys(inCollection: Storage.closedGroupPrivateKeyCollection)) + } + return result + } + + public func isClosedGroup(_ publicKey: String) -> Bool { + getUserClosedGroupPublicKeys().contains(publicKey) + } + + // MARK: Jobs + public func persist(_ job: Job, using transaction: Any) { fatalError("Not implemented.") } + public func markJobAsSucceeded(_ job: Job, using transaction: Any) { fatalError("Not implemented.") } + public func markJobAsFailed(_ job: Job, using transaction: Any) { fatalError("Not implemented.") } + + // MARK: Authorization + private static func getAuthTokenCollection(for server: String) -> String { + return (server == FileServerAPI.server) ? "LokiStorageAuthTokenCollection" : "LokiGroupChatAuthTokenCollection" + } + + public func getAuthToken(for server: String) -> String? { + let collection = Storage.getAuthTokenCollection(for: server) + var result: String? = nil + Storage.read { transaction in + result = transaction.object(forKey: server, inCollection: collection) as? String + } + return result + } + + public func setAuthToken(for server: String, to newValue: String, using transaction: Any) { + let collection = Storage.getAuthTokenCollection(for: server) + (transaction as! YapDatabaseReadWriteTransaction).setObject(newValue, forKey: server, inCollection: collection) + } + + public func removeAuthToken(for server: String, using transaction: Any) { + let collection = Storage.getAuthTokenCollection(for: server) + (transaction as! YapDatabaseReadWriteTransaction).removeObject(forKey: server, inCollection: collection) + } + + // MARK: Open Group Public Keys + private static let openGroupPublicKeyCollection = "LokiOpenGroupPublicKeyCollection" + + public func getOpenGroupPublicKey(for server: String) -> String? { + var result: String? = nil + Storage.read { transaction in + result = transaction.object(forKey: server, inCollection: Storage.openGroupPublicKeyCollection) as? String + } + return result + } + + public func setOpenGroupPublicKey(for server: String, to newValue: String, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).setObject(newValue, forKey: server, inCollection: Storage.openGroupPublicKeyCollection) + } + + // MARK: Last Message Server ID + private static let lastMessageServerIDCollection = "LokiGroupChatLastMessageServerIDCollection" + + public func getLastMessageServerID(for group: UInt64, on server: String) -> UInt64? { + var result: UInt64? = nil + Storage.read { transaction in + result = transaction.object(forKey: "\(server).\(group)", inCollection: Storage.lastMessageServerIDCollection) as? UInt64 + } + return result + } + + public func setLastMessageServerID(for group: UInt64, on server: String, to newValue: UInt64, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).setObject(newValue, forKey: "\(server).\(group)", inCollection: Storage.lastMessageServerIDCollection) + } + + public func removeLastMessageServerID(for group: UInt64, on server: String, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).removeObject(forKey: "\(server).\(group)", inCollection: Storage.lastMessageServerIDCollection) + } + + // MARK: Last Deletion Server ID + private static let lastDeletionServerIDCollection = "LokiGroupChatLastDeletionServerIDCollection" + + public func getLastDeletionServerID(for group: UInt64, on server: String) -> UInt64? { + var result: UInt64? = nil + Storage.read { transaction in + result = transaction.object(forKey: "\(server).\(group)", inCollection: Storage.lastDeletionServerIDCollection) as? UInt64 + } + return result + } + + public func setLastDeletionServerID(for group: UInt64, on server: String, to newValue: UInt64, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).setObject(newValue, forKey: "\(server).\(group)", inCollection: Storage.lastDeletionServerIDCollection) + } + + public func removeLastDeletionServerID(for group: UInt64, on server: String, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).removeObject(forKey: "\(server).\(group)", inCollection: Storage.lastDeletionServerIDCollection) + } + + // MARK: Open Group Metadata + private static let openGroupUserCountCollection = "LokiPublicChatUserCountCollection" + private static let openGroupMessageIDCollection = "LKMessageIDCollection" + + public func setUserCount(to newValue: Int, forOpenGroupWithID openGroupID: String, using transaction: Any) { + (transaction as! YapDatabaseReadWriteTransaction).setObject(newValue, forKey: openGroupID, inCollection: Storage.openGroupUserCountCollection) + } + + public func getIDForMessage(withServerID serverID: UInt64) -> UInt64? { + var result: UInt64? = nil + Storage.read { transaction in + result = transaction.object(forKey: String(serverID), inCollection: Storage.openGroupMessageIDCollection) as? UInt64 + } + return result + } + + public func setOpenGroupDisplayName(to displayName: String, for publicKey: String, on channel: UInt64, server: String, using transaction: Any) { + let collection = "\(server).\(channel)" // FIXME: This should be a proper collection + (transaction as! YapDatabaseReadWriteTransaction).setObject(displayName, forKey: publicKey, inCollection: collection) + } + + public func setLastProfilePictureUploadDate(_ date: Date) { + UserDefaults.standard[.lastProfilePictureUpload] = date + } +} diff --git a/Session/Database/Storage+SessionSnodeKit.swift b/Session/Database/Storage+SessionSnodeKit.swift index 356cd72c9..032fcd439 100644 --- a/Session/Database/Storage+SessionSnodeKit.swift +++ b/Session/Database/Storage+SessionSnodeKit.swift @@ -2,7 +2,7 @@ extension Storage : SessionSnodeKitStorageProtocol { // MARK: Onion Request Paths - internal static let onionRequestPathCollection = "LokiOnionRequestPathCollection" + private static let onionRequestPathCollection = "LokiOnionRequestPathCollection" public func getOnionRequestPaths() -> [OnionRequestAPI.Path] { let collection = Storage.onionRequestPathCollection diff --git a/Session/Database/Storage+Shared.swift b/Session/Database/Storage+Shared.swift index 10741e332..7910e7532 100644 --- a/Session/Database/Storage+Shared.swift +++ b/Session/Database/Storage+Shared.swift @@ -7,7 +7,17 @@ extension Storage { Storage.writeSync { work($0) } } + public func withAsync(_ work: @escaping (Any) -> Void, completion: @escaping () -> Void) { + Storage.write(with: { work($0) }, completion: completion) + } + public func getUserPublicKey() -> String? { return OWSIdentityManager.shared().identityKeyPair()?.publicKey.toHexString() } + + public func getUserKeyPair() -> ECKeyPair? { + return OWSIdentityManager.shared().identityKeyPair() + } + + public func getUserDisplayName() -> String? { fatalError() } } diff --git a/SessionMessagingKit/Configuration.swift b/SessionMessagingKit/Configuration.swift index 649cc8654..525b9f9bb 100644 --- a/SessionMessagingKit/Configuration.swift +++ b/SessionMessagingKit/Configuration.swift @@ -13,7 +13,7 @@ public struct Configuration { internal static var shared: Configuration! } -public enum SessionMessagingKitX { // Just to make the external API nice +public enum SNMessagingKit { // Just to make the external API nice public static func configure( storage: SessionMessagingKitStorageProtocol, diff --git a/SessionMessagingKit/Open Groups/OpenGroupAPI.swift b/SessionMessagingKit/Open Groups/OpenGroupAPI.swift index 6690066e2..82ee5c6d7 100644 --- a/SessionMessagingKit/Open Groups/OpenGroupAPI.swift +++ b/SessionMessagingKit/Open Groups/OpenGroupAPI.swift @@ -122,7 +122,7 @@ public final class OpenGroupAPI : DotNetAPI { SNLog("Ignoring open group message with invalid signature.") return nil } - let existingMessageID = storage.getIDForMessage(withServerID: UInt(result.serverID!)) + let existingMessageID = storage.getIDForMessage(withServerID: result.serverID!) guard existingMessageID == nil else { SNLog("Ignoring duplicate open group message.") return nil diff --git a/SessionMessagingKit/Storage.swift b/SessionMessagingKit/Storage.swift index 5d050fad6..2b3455892 100644 --- a/SessionMessagingKit/Storage.swift +++ b/SessionMessagingKit/Storage.swift @@ -2,8 +2,8 @@ import SessionProtocolKit public protocol SessionMessagingKitStorageProtocol { - func with(_ work: (Any) -> Void) - func withAsync(_ work: (Any) -> Void, completion: () -> Void) + func with(_ work: @escaping (Any) -> Void) + func withAsync(_ work: @escaping (Any) -> Void, completion: @escaping () -> Void) func getUserPublicKey() -> String? func getUserKeyPair() -> ECKeyPair? @@ -20,14 +20,14 @@ public protocol SessionMessagingKitStorageProtocol { func removeAuthToken(for server: String, using transaction: Any) func getOpenGroupPublicKey(for server: String) -> String? func setOpenGroupPublicKey(for server: String, to newValue: String, using transaction: Any) - func getLastMessageServerID(for group: UInt64, on server: String) -> UInt? + func getLastMessageServerID(for group: UInt64, on server: String) -> UInt64? func setLastMessageServerID(for group: UInt64, on server: String, to newValue: UInt64, using transaction: Any) func removeLastMessageServerID(for group: UInt64, on server: String, using transaction: Any) func getLastDeletionServerID(for group: UInt64, on server: String) -> UInt64? func setLastDeletionServerID(for group: UInt64, on server: String, to newValue: UInt64, using transaction: Any) func removeLastDeletionServerID(for group: UInt64, on server: String, using transaction: Any) - func setUserCount(to newValue: Int, forOpenGroupWithID: String, using transaction: Any) - func getIDForMessage(withServerID serverID: UInt) -> UInt? + func setUserCount(to newValue: Int, forOpenGroupWithID openGroupID: String, using transaction: Any) + func getIDForMessage(withServerID serverID: UInt64) -> UInt64? func setOpenGroupDisplayName(to displayName: String, for publicKey: String, on channel: UInt64, server: String, using transaction: Any) func setLastProfilePictureUploadDate(_ date: Date) // Stored in user defaults so no transaction is needed } diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 0a7ef7111..640ba3bc0 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -801,6 +801,8 @@ C3548F0624456447009433A8 /* PNModeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3548F0524456447009433A8 /* PNModeVC.swift */; }; C3548F0824456AB6009433A8 /* UIView+Wrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3548F0724456AB6009433A8 /* UIView+Wrapping.swift */; }; C354E75A23FE2A7600CE22E3 /* BaseVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C354E75923FE2A7600CE22E3 /* BaseVC.swift */; }; + C3550A03255DD6D900194B6A /* AppDelegate+OpenGroupAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3550A02255DD6D900194B6A /* AppDelegate+OpenGroupAPI.swift */; }; + C3550A1D255DD73500194B6A /* Storage+SessionMessagingKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3550A1C255DD73500194B6A /* Storage+SessionMessagingKit.swift */; }; C35E8AA82485C85800ACB629 /* GeoLite2-Country-Locations-English.csv in Resources */ = {isa = PBXBuildFile; fileRef = C35E8AA52485C85400ACB629 /* GeoLite2-Country-Locations-English.csv */; }; C35E8AA92485C85800ACB629 /* GeoLite2-Country-Blocks-IPv4.csv in Resources */ = {isa = PBXBuildFile; fileRef = C35E8AA62485C85600ACB629 /* GeoLite2-Country-Blocks-IPv4.csv */; }; C35E8AAE2485E51D00ACB629 /* IP2Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35E8AAD2485E51D00ACB629 /* IP2Country.swift */; }; @@ -2165,6 +2167,8 @@ C3548F0524456447009433A8 /* PNModeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PNModeVC.swift; sourceTree = ""; }; 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 = ""; }; + C3550A02255DD6D900194B6A /* AppDelegate+OpenGroupAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+OpenGroupAPI.swift"; sourceTree = ""; }; + C3550A1C255DD73500194B6A /* Storage+SessionMessagingKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+SessionMessagingKit.swift"; sourceTree = ""; }; C35E8AA22485C72300ACB629 /* SwiftCSV.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftCSV.framework; path = ThirdParty/Carthage/Build/iOS/SwiftCSV.framework; sourceTree = ""; }; C35E8AA52485C85400ACB629 /* GeoLite2-Country-Locations-English.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "GeoLite2-Country-Locations-English.csv"; sourceTree = ""; }; C35E8AA62485C85600ACB629 /* GeoLite2-Country-Blocks-IPv4.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "GeoLite2-Country-Blocks-IPv4.csv"; sourceTree = ""; }; @@ -3272,6 +3276,7 @@ C31F812425258F9C00DD9FD9 /* Database */ = { isa = PBXGroup; children = ( + C3550A1C255DD73500194B6A /* Storage+SessionMessagingKit.swift */, C3F0A619255C9902007BE2A3 /* Storage+SessionProtocolKit.swift */, C3F0A607255C98A6007BE2A3 /* Storage+SessionSnodeKit.swift */, C3F0A5FD255C988A007BE2A3 /* Storage+Shared.swift */, @@ -4477,6 +4482,7 @@ isa = PBXGroup; children = ( C3F0A58F255C8E3D007BE2A3 /* Meta */, + C3550A02255DD6D900194B6A /* AppDelegate+OpenGroupAPI.swift */, C3F0A62B255C9937007BE2A3 /* AppDelegate+SharedSenderKeys.swift */, C3F0A5EB255C970D007BE2A3 /* Configuration.swift */, B8CCF63B239757C10091D419 /* Components */, @@ -6159,6 +6165,7 @@ 34D99C931F2937CC00D284D6 /* OWSAnalytics.swift in Sources */, B8783E9E23EB948D00404FB8 /* UILabel+Interaction.swift in Sources */, B80C6B5B2384C7F900FDBC8B /* DeviceNameModalDelegate.swift in Sources */, + C3550A03255DD6D900194B6A /* AppDelegate+OpenGroupAPI.swift in Sources */, 340FC8B8204DAC8D007AEB0F /* AddToGroupViewController.m in Sources */, B893063F2383961A005EAA8E /* ScanQRCodeWrapperVC.swift in Sources */, B879D449247E1BE300DB3608 /* PathVC.swift in Sources */, @@ -6268,6 +6275,7 @@ 340FC8AB204DAC8D007AEB0F /* DomainFrontingCountryViewController.m in Sources */, 4C586926224FAB83003FD070 /* AVAudioSession+OWS.m in Sources */, 3496744D2076768700080B5F /* OWSMessageBubbleView.m in Sources */, + C3550A1D255DD73500194B6A /* Storage+SessionMessagingKit.swift in Sources */, C331FFF42558FF0300070591 /* PNOptionView.swift in Sources */, 34B3F8751E8DF1700035BE1A /* CallViewController.swift in Sources */, 4C4AE6A1224AF35700D4AF6F /* SendMediaNavigationController.swift in Sources */, From 262c5ebe4a6dad44de755a01fd077f00e9db71b8 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 13 Nov 2020 08:47:14 +1100 Subject: [PATCH 11/14] Fix incorrect tag --- SessionMessagingKit/Open Groups/OpenGroupAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SessionMessagingKit/Open Groups/OpenGroupAPI.swift b/SessionMessagingKit/Open Groups/OpenGroupAPI.swift index 82ee5c6d7..f88017434 100644 --- a/SessionMessagingKit/Open Groups/OpenGroupAPI.swift +++ b/SessionMessagingKit/Open Groups/OpenGroupAPI.swift @@ -17,7 +17,7 @@ public final class OpenGroupAPI : DotNetAPI { public static let profilePictureType = "network.loki.messenger.avatar" - @objc public static let openGroupMessageType = "network.loki.messenger.openGroup" + @objc public static let openGroupMessageType = "network.loki.messenger.publicChat" // MARK: Open Group Public Key Validation public static func getOpenGroupServerPublicKey(for server: String) -> Promise { From 35c835f35041d772c0695d73f287db8305766dd7 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 13 Nov 2020 09:08:20 +1100 Subject: [PATCH 12/14] Update build number --- Signal.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index d011aa227..1b56de932 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4157,7 +4157,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4219,7 +4219,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4273,7 +4273,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4343,7 +4343,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4405,7 +4405,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4468,7 +4468,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4669,7 +4669,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4736,7 +4736,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 142; + CURRENT_PROJECT_VERSION = 143; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From a5e9d8973ae80b3e93ce9e800ce24ff776850964 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 13 Nov 2020 09:54:36 +1100 Subject: [PATCH 13/14] Fix indentation --- Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile b/Podfile index 79bdddf9d..d244f3b0f 100644 --- a/Podfile +++ b/Podfile @@ -132,7 +132,7 @@ end def set_minimum_deployment_target(installer) installer.pods_project.targets.each do |target| target.build_configurations.each do |build_configuration| - build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' + build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' end end end From 877751445da70082d2666f58780fdb7c7f74d7b9 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 13 Nov 2020 10:22:50 +1100 Subject: [PATCH 14/14] Clean --- Podfile | 9 +++---- Podfile.lock | 2 +- Signal.xcodeproj/project.pbxproj | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Podfile b/Podfile index d244f3b0f..caf6d4ca6 100644 --- a/Podfile +++ b/Podfile @@ -2,7 +2,6 @@ platform :ios, '12.0' source 'https://github.com/CocoaPods/Specs.git' use_frameworks! -inhibit_all_warnings! target 'Session' do pod 'AFNetworking', inhibit_warnings: true @@ -130,9 +129,9 @@ def enable_extension_support_for_pure_layout(installer) end def set_minimum_deployment_target(installer) - installer.pods_project.targets.each do |target| - target.build_configurations.each do |build_configuration| - build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' - end + installer.pods_project.targets.each do |target| + target.build_configurations.each do |build_configuration| + build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' end + end end diff --git a/Podfile.lock b/Podfile.lock index 9619ab8eb..54a6863c1 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -230,6 +230,6 @@ SPEC CHECKSUMS: YYImage: 6db68da66f20d9f169ceb94dfb9947c3867b9665 ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb -PODFILE CHECKSUM: 1aad5fbd49d168d2f50da0b3b3e515247f1ce291 +PODFILE CHECKSUM: 3489ed70ea51f2bf705bf99703efc71d697de373 COCOAPODS: 1.10.0.rc.1 diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 3a6cde86a..17796af1f 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -6488,6 +6488,13 @@ GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "SessionShareExtension/Meta/SignalShareExtension-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "COCOAPODS=1", + "$(inherited)", + "SQLITE_HAS_CODEC=1", + "PURELAYOUT_APP_EXTENSIONS=1", + ); GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; @@ -6551,6 +6558,13 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "SessionShareExtension/Meta/SignalShareExtension-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "COCOAPODS=1", + "$(inherited)", + "SQLITE_HAS_CODEC=1", + "PURELAYOUT_APP_EXTENSIONS=1", + ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -6602,6 +6616,13 @@ GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "COCOAPODS=1", + "$(inherited)", + "SQLITE_HAS_CODEC=1", + "PURELAYOUT_APP_EXTENSIONS=1", + ); GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = SessionPushNotificationExtension/Meta/Info.plist; @@ -6666,6 +6687,13 @@ FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "COCOAPODS=1", + "$(inherited)", + "SQLITE_HAS_CODEC=1", + "PURELAYOUT_APP_EXTENSIONS=1", + ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -6847,6 +6875,13 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREFIX_HEADER = "SignalUtilitiesKit/Meta/SignalUtilitiesKit-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "COCOAPODS=1", + "$(inherited)", + "SQLITE_HAS_CODEC=1", + "PURELAYOUT_APP_EXTENSIONS=1", + ); GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = SignalUtilitiesKit/Meta/Info.plist; @@ -6917,6 +6952,13 @@ GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_PREFIX_HEADER = "SignalUtilitiesKit/Meta/SignalUtilitiesKit-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "COCOAPODS=1", + "$(inherited)", + "SQLITE_HAS_CODEC=1", + "PURELAYOUT_APP_EXTENSIONS=1", + ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -7649,6 +7691,7 @@ "DEBUG=1", "$(inherited)", HAVE_CONFIG_H, + "PURELAYOUT_APP_EXTENSIONS=1", ); GCC_STRICT_ALIASING = NO; GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = NO; @@ -7716,6 +7759,7 @@ "$(inherited)", HAVE_CONFIG_H, "RELEASE=1", + "PURELAYOUT_APP_EXTENSIONS=1", ); GCC_STRICT_ALIASING = NO; GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = NO;