From af913305b0add2fcd825d1bf200cecc3c81c0454 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 25 Feb 2020 15:47:43 +1100 Subject: [PATCH 1/8] fix typo --- SignalServiceKit/src/Messages/OWSMessageDecrypter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index 24b45947a..aba11134a 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -431,7 +431,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes sessionStore:self.primaryStorage preKeyStore:self.primaryStorage signedPreKeyStore:self.primaryStorage - identityKeyStore:self.primaryStorage + identityKeyStore:self.identityManager recipientID:recipientId deviceID:deviceId]; From 6ecbc755eac4633d9e9ae194b85ac65f37122171 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 25 Feb 2020 11:52:36 +0700 Subject: [PATCH 2/8] Update version number --- Signal.xcodeproj/project.pbxproj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 4ebf16bcb..12acb7f58 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4230,7 +4230,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 46; + CURRENT_PROJECT_VERSION = 47; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4244,7 +4244,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.0.4; + MARKETING_VERSION = 1.0.5; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.share-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4292,7 +4292,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 46; + CURRENT_PROJECT_VERSION = 47; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4311,7 +4311,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.0.4; + MARKETING_VERSION = 1.0.5; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.share-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4346,7 +4346,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 46; + CURRENT_PROJECT_VERSION = 47; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4365,7 +4365,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.0.4; + MARKETING_VERSION = 1.0.5; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.utilities"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -4415,7 +4415,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 46; + CURRENT_PROJECT_VERSION = 47; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4439,7 +4439,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.0.4; + MARKETING_VERSION = 1.0.5; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.utilities"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -4624,7 +4624,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 46; + CURRENT_PROJECT_VERSION = 47; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4659,7 +4659,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.0.4; + MARKETING_VERSION = 1.0.5; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; @@ -4691,7 +4691,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 46; + CURRENT_PROJECT_VERSION = 47; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4726,7 +4726,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.0.4; + MARKETING_VERSION = 1.0.5; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; From c0dda78e52c472e6e63f1c7707379aa960550373 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 25 Feb 2020 16:32:05 +0700 Subject: [PATCH 3/8] Debug --- SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift | 5 +++-- SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift | 5 +++-- SignalServiceKit/src/Loki/API/LokiHttpClient.swift | 1 + SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift index 61ec13fce..50d363008 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift @@ -32,6 +32,7 @@ public extension LokiAPI { // MARK: Internal API internal static func getRandomSnode() -> Promise { + // All of this has to happen on DispatchQueue.global() due to the way OWSMessageManager works if randomSnodePool.isEmpty { let target = seedNodePool.randomElement()! let url = URL(string: "\(target)/json_rpc")! @@ -49,7 +50,7 @@ public extension LokiAPI { ] ]) print("[Loki] Invoking get_n_service_nodes on \(target).") - return TSNetworkManager.shared().perform(request).map(on: DispatchQueue.global()) { intermediate in + return TSNetworkManager.shared().perform(request, withCompletionQueue: DispatchQueue.global()).map(on: DispatchQueue.global()) { intermediate in let rawResponse = intermediate.responseObject guard let json = rawResponse as? JSON, let intermediate = json["result"] as? JSON, let rawTargets = intermediate["service_node_states"] as? [JSON] else { throw LokiAPIError.randomSnodePoolUpdatingFailed } randomSnodePool = try Set(rawTargets.flatMap { rawTarget in @@ -61,7 +62,7 @@ public extension LokiAPI { }) // randomElement() uses the system's default random generator, which is cryptographically secure return randomSnodePool.randomElement()! - }.recover { error -> Promise in + }.recover(on: DispatchQueue.global()) { error -> Promise in print("[Loki] Failed to contact seed node at: \(target).") throw error }.retryingIfNeeded(maxRetryCount: 16) // The seed nodes have historically been unreliable diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift index 05d7f1fd2..a291edcf0 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift @@ -44,6 +44,7 @@ internal class LokiFileServerProxy : LokiHTTPClient { } internal func performLokiFileServerNSURLRequest(_ request: NSURLRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise { + // All of this has to happen on DispatchQueue.global() due to the way OWSMessageManager works var headers = getCanonicalHeaders(for: request) return Promise { [server = self.server, keyPair = self.keyPair, httpSession = self.httpSession] seal in DispatchQueue.global().async { @@ -116,9 +117,9 @@ internal class LokiFileServerProxy : LokiHTTPClient { let uncheckedJSON = try? JSONSerialization.jsonObject(with: uncheckedJSONAsData, options: .allowFragments) as? JSON guard let json = uncheckedJSON else { throw HTTPError.networkError(code: -1, response: nil, underlyingError: Error.proxyResponseParsingFailed) } return json - }.done { rawResponse in + }.done(on: DispatchQueue.global()) { rawResponse in seal.fulfill(rawResponse) - }.catch { error in + }.catch(on: DispatchQueue.global()) { error in print("[Loki] File server proxy request failed with error: \(error.localizedDescription).") seal.reject(HTTPError.from(error: error) ?? error) } diff --git a/SignalServiceKit/src/Loki/API/LokiHttpClient.swift b/SignalServiceKit/src/Loki/API/LokiHttpClient.swift index 202059f9b..8f9670f17 100644 --- a/SignalServiceKit/src/Loki/API/LokiHttpClient.swift +++ b/SignalServiceKit/src/Loki/API/LokiHttpClient.swift @@ -10,6 +10,7 @@ internal class LokiHTTPClient { securityPolicy.validatesDomainName = false result.securityPolicy = securityPolicy result.responseSerializer = AFHTTPResponseSerializer() + result.completionQueue = DispatchQueue.global() // All of this has to happen on DispatchQueue.global() due to the way OWSMessageManager works return result }() diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index b6ad356a1..db0bdccb4 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1406,7 +1406,7 @@ NS_ASSUME_NONNULL_BEGIN }).catchOn(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(NSError *error) { dispatch_semaphore_signal(semaphore); }) retainUntilComplete]; - dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC)); + dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC)); } if (groupId.length > 0) { From 1c44a65f2c3e66d9472d8464cb033c7d1c716149 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 26 Feb 2020 09:58:36 +0700 Subject: [PATCH 4/8] Fix database handling issues --- SignalServiceKit/src/Loki/API/LokiAPI.swift | 2 +- SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift | 2 +- SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index 126eac01b..656a9fd65 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -142,7 +142,7 @@ public final class LokiAPI : NSObject { destinations.append(contentsOf: slaveDestinations) seal.fulfill(destinations) } - if let transaction = transaction { + if let transaction = transaction, transaction.connection.pendingTransactionCount != 0 { getDestinationsInternal(in: transaction) } else { storage.dbReadConnection.read { transaction in diff --git a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift index 3a021b5c4..5fc5b97b3 100644 --- a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift @@ -57,7 +57,7 @@ public class LokiDotNetAPI : NSObject { func setAuthTokenInternal(in transaction: YapDatabaseReadWriteTransaction) { transaction.setObject(newValue, forKey: server, inCollection: authTokenCollection) } - if let transaction = transaction { + if let transaction = transaction, transaction.connection.pendingTransactionCount != 0 { setAuthTokenInternal(in: transaction) } else { storage.dbReadWriteConnection.readWrite { transaction in diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift index 586e10069..fb8a4e5dc 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift @@ -76,9 +76,16 @@ public final class LokiFileServerAPI : LokiDotNetAPI { } }) }.map(on: DispatchQueue.global()) { deviceLinks -> Set in - storage.dbReadWriteConnection.readWrite { transaction in + func setDeviceLinks(in transaction: YapDatabaseReadWriteTransaction) { storage.setDeviceLinks(deviceLinks, in: transaction) } + if let transaction = transaction, transaction.connection.pendingTransactionCount != 0 { + setDeviceLinks(in: transaction) + } else { + storage.dbReadWriteConnection.readWrite { transaction in + setDeviceLinks(in: transaction) + } + } return deviceLinks } } From c26457cf7453fddca2ba5eda0f403d7c598bd8a8 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 26 Feb 2020 09:59:13 +0700 Subject: [PATCH 5/8] Update build number --- Signal.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 12acb7f58..297b2117f 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4230,7 +4230,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 47; + CURRENT_PROJECT_VERSION = 48; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4292,7 +4292,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 47; + CURRENT_PROJECT_VERSION = 48; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4346,7 +4346,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 47; + CURRENT_PROJECT_VERSION = 48; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4415,7 +4415,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 47; + CURRENT_PROJECT_VERSION = 48; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4624,7 +4624,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 47; + CURRENT_PROJECT_VERSION = 48; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4691,7 +4691,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 47; + CURRENT_PROJECT_VERSION = 48; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From f3c649e351eab2dbaee87260aa6c81f65d9db75d Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 26 Feb 2020 14:11:33 +1100 Subject: [PATCH 6/8] fix the issue of input disappearing after asking for permission of using camera or photo library --- .../ConversationViewController.m | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 741231a4e..68eace1e0 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3081,7 +3081,11 @@ typedef enum : NSUInteger { - (void)sendMediaNavDidCancel:(SendMediaNavigationController *)sendMediaNavigationController { - [self dismissViewControllerAnimated:YES completion:nil]; + [self dismissViewControllerAnimated:YES completion:^{ + if (!self.isFirstResponder) { + [self becomeFirstResponder]; + } + }]; } - (void)sendMediaNav:(SendMediaNavigationController *)sendMediaNavigationController @@ -3096,15 +3100,16 @@ typedef enum : NSUInteger { // the new message scroll into view. [self scrollToBottomAnimated:NO]; - [self dismissViewControllerAnimated:YES - completion:^{ -// OWSAssertDebug(self.isFirstResponder); - if (@available(iOS 10, *)) { - // do nothing - } else { - [self reloadInputViews]; - } - }]; + [self dismissViewControllerAnimated:YES completion:^{ + if (!self.isFirstResponder) { + [self becomeFirstResponder]; + } + if (@available(iOS 10, *)) { + // do nothing + } else { + [self reloadInputViews]; + } + }]; } - (nullable NSString *)sendMediaNavInitialMessageText:(SendMediaNavigationController *)sendMediaNavigationController From 3479fc433335ef7995df5143f612f5745d5dbead Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 28 Feb 2020 09:58:45 +0700 Subject: [PATCH 7/8] Reduce code duplication --- .../View Controllers/DeviceLinkingModal.swift | 4 ++-- .../View Controllers/NewClosedGroupVC.swift | 3 +-- SignalMessaging/contacts/OWSSyncManager.m | 9 ++++----- .../src/Contacts/Threads/TSGroupThread.h | 2 +- .../src/Contacts/Threads/TSGroupThread.m | 8 ++++---- .../src/Devices/OWSGroupsOutputStream.m | 8 +++++--- .../src/Loki/Messaging/GroupParser.swift | 8 ++------ .../DeviceSyncing/OWSSyncGroupsMessage.m | 2 +- .../src/Messages/OWSMessageManager.m | 9 +++++---- .../src/Messages/OWSMessageSender.h | 2 +- .../src/Messages/OWSMessageSender.m | 17 ++++------------- 11 files changed, 30 insertions(+), 42 deletions(-) diff --git a/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift b/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift index 195dd5669..2ac78e166 100644 --- a/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift +++ b/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift @@ -165,8 +165,8 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate { let linkingAuthorizationMessage = DeviceLinkingUtilities.getLinkingAuthorizationMessage(for: deviceLink) ThreadUtil.enqueue(linkingAuthorizationMessage) SSKEnvironment.shared.messageSender.send(linkingAuthorizationMessage, success: { - let _ = [SSKEnvironment.shared.syncManager.syncAllContacts(), - SSKEnvironment.shared.syncManager.syncAllGroups()] + SSKEnvironment.shared.syncManager.syncAllContacts() + SSKEnvironment.shared.syncManager.syncAllGroups() }) { _ in print("[Loki] Failed to send device link authorization message.") } diff --git a/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift b/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift index 23d1aee5f..4a7008b48 100644 --- a/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift +++ b/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift @@ -173,9 +173,8 @@ final class NewClosedGroupVC : UIViewController, UITableViewDataSource, UITableV storage.dbReadConnection.readWrite { transaction in masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: userHexEncodedPublicKey, in: transaction) ?? userHexEncodedPublicKey } - let members = [String](selectedContacts) + [ masterHexEncodedPublicKey ] + let members = selectedContacts + [ masterHexEncodedPublicKey ] let admins = [ masterHexEncodedPublicKey ] - let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(Randomness.generateRandomBytes(kGroupIdLength)!.toHexString()) let group = TSGroupModel(title: name, memberIds: members, image: nil, groupId: groupID, groupType: .closedGroup, adminIds: admins) let thread = TSGroupThread.getOrCreateThread(with: group) diff --git a/SignalMessaging/contacts/OWSSyncManager.m b/SignalMessaging/contacts/OWSSyncManager.m index d5c2c4574..52873e7f4 100644 --- a/SignalMessaging/contacts/OWSSyncManager.m +++ b/SignalMessaging/contacts/OWSSyncManager.m @@ -330,9 +330,8 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag NSMutableArray *promises = @[].mutableCopy; [TSGroupThread enumerateCollectionObjectsUsingBlock:^(id obj, BOOL *stop) { if (![obj isKindOfClass:[TSGroupThread class]]) { - if (![obj isKindOfClass:[TSContactThread class]]) { - OWSLogWarn(@"Ignoring non group thread in thread collection: %@", obj); - + if (![obj isKindOfClass:[TSContactThread class]]) { // FIXME: Isn't this redundant? + OWSLogWarn(@"Ignoring non-group thread in thread collection: %@.", obj); } return; } @@ -355,11 +354,11 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag AnyPromise *promise = [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) { [self.messageSender sendMessage:syncGroupsMessage success:^{ - OWSLogInfo(@"Successfully sent groups sync message."); + OWSLogInfo(@"Successfully sent group sync message."); resolve(@(1)); } failure:^(NSError *error) { - OWSLogError(@"Failed to send groups sync message with error: %@.", error); + OWSLogError(@"Failed to send group sync message due to error: %@.", error); resolve(error); }]; }]; diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index a243daa7f..3acc8a99b 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -39,7 +39,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; - (BOOL)isLocalUserInGroup; - (BOOL)isLocalUserInGroupWithTransaction:(YapDatabaseReadTransaction *)transaction; - (BOOL)isUserInGroup:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction; -- (BOOL)isUserAdminForGroup:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction; +- (BOOL)isUserAdminInGroup:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction; // all group threads containing recipient as a member + (NSArray *)groupThreadsWithRecipientId:(NSString *)recipientId diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index 98b80ecc3..3995c0c35 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -211,7 +211,7 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific return [linkedDeviceHexEncodedPublicKeys intersectsSet:[NSSet setWithArray:self.groupModel.groupMemberIds]]; } -- (BOOL)isUserAdminForGroup:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction +- (BOOL)isUserAdminInGroup:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction { if (hexEncodedPublicKey == nil) { return NO; } NSSet *linkedDeviceHexEncodedPublicKeys = [LKDatabaseUtilities getLinkedDeviceHexEncodedPublicKeysFor:hexEncodedPublicKey in:transaction]; @@ -241,13 +241,13 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { - NSMutableSet *newGroupMemberIds = [NSMutableSet setWithArray:self.groupModel.groupMemberIds]; + NSMutableSet *newGroupMemberIDs = [NSMutableSet setWithArray:self.groupModel.groupMemberIds]; NSString *userHexEncodedPublicKey = TSAccountManager.localNumber; if (userHexEncodedPublicKey != nil) { NSSet *linkedDeviceHexEncodedPublicKeys = [LKDatabaseUtilities getLinkedDeviceHexEncodedPublicKeysFor:userHexEncodedPublicKey in:transaction]; - [newGroupMemberIds minusSet:linkedDeviceHexEncodedPublicKeys]; + [newGroupMemberIDs minusSet:linkedDeviceHexEncodedPublicKeys]; } - self.groupModel.groupMemberIds = newGroupMemberIds.allObjects; + self.groupModel.groupMemberIds = newGroupMemberIDs.allObjects; [self saveWithTransaction:transaction]; } diff --git a/SignalServiceKit/src/Devices/OWSGroupsOutputStream.m b/SignalServiceKit/src/Devices/OWSGroupsOutputStream.m index fe14f15c3..89ce9e763 100644 --- a/SignalServiceKit/src/Devices/OWSGroupsOutputStream.m +++ b/SignalServiceKit/src/Devices/OWSGroupsOutputStream.m @@ -73,9 +73,11 @@ NS_ASSUME_NONNULL_BEGIN [self writeUInt32:groupDataLength]; [self writeData:groupData]; -// if (avatarPng) { -// [self writeData:avatarPng]; -// } + /* + if (avatarPng) { + [self writeData:avatarPng]; + } + */ } @end diff --git a/SignalServiceKit/src/Loki/Messaging/GroupParser.swift b/SignalServiceKit/src/Loki/Messaging/GroupParser.swift index 3c3fd68b1..2a42e3d58 100644 --- a/SignalServiceKit/src/Loki/Messaging/GroupParser.swift +++ b/SignalServiceKit/src/Loki/Messaging/GroupParser.swift @@ -21,12 +21,8 @@ let protoAsData = data[index..<(index+sizeAsInt)] guard let proto = try? SSKProtoGroupDetails.parseData(protoAsData) else { break } index += sizeAsInt - var groupModel = TSGroupModel.init(title: proto.name, - memberIds: proto.members, - image: nil, - groupId: proto.id, - groupType: GroupType.closedGroup, - adminIds: proto.admins) + var groupModel = TSGroupModel(title: proto.name, memberIds: proto.members, image: nil, + groupId: proto.id, groupType: GroupType.closedGroup, adminIds: proto.admins) result.append(groupModel) } return result diff --git a/SignalServiceKit/src/Messages/DeviceSyncing/OWSSyncGroupsMessage.m b/SignalServiceKit/src/Messages/DeviceSyncing/OWSSyncGroupsMessage.m index 9ee62dd34..de6f8022a 100644 --- a/SignalServiceKit/src/Messages/DeviceSyncing/OWSSyncGroupsMessage.m +++ b/SignalServiceKit/src/Messages/DeviceSyncing/OWSSyncGroupsMessage.m @@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN SSKProtoSyncMessageGroups *_Nullable groupsProto = [groupsBuilder buildAndReturnError:&error]; if (error || !groupsProto) { - OWSFailDebug(@"could not build protobuf: %@", error); + OWSFailDebug(@"Couldn't build protobuf due to error: %@.", error); return nil; } diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index ac3d4806d..10ae76c08 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1077,7 +1077,7 @@ NS_ASSUME_NONNULL_BEGIN [self.identityManager throws_processIncomingSyncMessage:syncMessage.verified transaction:transaction]; } else if (syncMessage.contacts != nil) { if (wasSentByMasterDevice && syncMessage.contacts.data.length > 0) { - OWSLogInfo(@"[Loki] Received contact sync message."); + [LKLogger print:@"[Loki] Received contact sync message."]; NSData *data = syncMessage.contacts.data; ContactParser *parser = [[ContactParser alloc] initWithData:data]; NSArray *hexEncodedPublicKeys = [parser parseHexEncodedPublicKeys]; @@ -1088,7 +1088,8 @@ NS_ASSUME_NONNULL_BEGIN switch (friendRequestStatus) { case LKThreadFriendRequestStatusNone: { OWSMessageSender *messageSender = SSKEnvironment.shared.messageSender; - LKFriendRequestMessage *automatedFriendRequestMessage = [messageSender getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:hexEncodedPublicKey inThread:thread transaction:transaction]; + LKFriendRequestMessage *automatedFriendRequestMessage = [messageSender getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:hexEncodedPublicKey transaction:transaction]; + [automatedFriendRequestMessage saveWithTransaction:transaction]; [self.messageSenderJobQueue addMessage:automatedFriendRequestMessage transaction:transaction]; break; } @@ -1105,7 +1106,7 @@ NS_ASSUME_NONNULL_BEGIN } } else if (syncMessage.groups != nil) { if (wasSentByMasterDevice && syncMessage.groups.data.length > 0) { - OWSLogInfo(@"[Loki] Received group sync message."); + [LKLogger print:@"[Loki] Received group sync message."]; NSData *data = syncMessage.groups.data; GroupParser *parser = [[GroupParser alloc] initWithData:data]; NSArray *groupModels = [parser parseGroupModels]; @@ -1454,7 +1455,7 @@ NS_ASSUME_NONNULL_BEGIN switch (dataMessage.group.type) { case SSKProtoGroupContextTypeUpdate: { - if (oldGroupThread && ![oldGroupThread isUserAdminForGroup:hexEncodedPublicKey transaction:transaction]) { + if (oldGroupThread && ![oldGroupThread isUserAdminInGroup:hexEncodedPublicKey transaction:transaction]) { [LKLogger print:[NSString stringWithFormat:@"[Loki] Received a group update from a non-admin user for %@; ignoring.", [LKGroupUtilities getEncodedGroupID:groupId]]]; return nil; } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.h b/SignalServiceKit/src/Messages/OWSMessageSender.h index b6af35dc2..acdab71fe 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.h +++ b/SignalServiceKit/src/Messages/OWSMessageSender.h @@ -100,8 +100,8 @@ NS_SWIFT_NAME(MessageSender) failure:(void (^)(NSError *error))failureHandler; - (OWSMessageSend *)getSessionRestoreMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey; -- (LKFriendRequestMessage *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey inThread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction; - (OWSMessageSend *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey; +- (LKFriendRequestMessage *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)sendMessage:(OWSMessageSend *)messageSend; @end diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 168e67097..e54d7f908 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -937,9 +937,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return [[OWSMessageSend alloc] initWithMessage:message thread:thread recipient:recipient senderCertificate:senderCertificate udAccess:theirUDAccess localNumber:userHexEncodedPublicKey success:^{ } failure:^(NSError *error) { }]; } -- (LKFriendRequestMessage *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey inThread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction +- (LKFriendRequestMessage *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey transaction:(YapDatabaseReadWriteTransaction *)transaction { - thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; + TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; // Force hide slave device thread NSString *masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:hexEncodedPublicKey in:transaction]; thread.isForceHidden = masterHexEncodedPublicKey != nil && ![masterHexEncodedPublicKey isEqualToString:hexEncodedPublicKey]; @@ -950,26 +950,17 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; LKFriendRequestMessage *message = [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"Please accept to enable messages to be synced across devices" attachmentIds:[NSMutableArray new] expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil]; message.skipSave = YES; - [message saveWithTransaction:transaction]; return message; } - (OWSMessageSend *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey { __block TSContactThread *thread; + __block LKFriendRequestMessage *message; [OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; - // Force hide slave device thread - NSString *masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:hexEncodedPublicKey in:transaction]; - thread.isForceHidden = masterHexEncodedPublicKey != nil && ![masterHexEncodedPublicKey isEqualToString:hexEncodedPublicKey]; - if (thread.friendRequestStatus == LKThreadFriendRequestStatusNone || thread.friendRequestStatus == LKThreadFriendRequestStatusRequestExpired) { - [thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestSent withTransaction:transaction]; - } - [thread saveWithTransaction:transaction]; + message = [self getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:hexEncodedPublicKey transaction:transaction]; }]; - LKFriendRequestMessage *message = [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"Please accept to enable messages to be synced across devices" attachmentIds:[NSMutableArray new] - expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil]; - message.skipSave = YES; SignalRecipient *recipient = [[SignalRecipient alloc] initWithUniqueId:hexEncodedPublicKey]; NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey; SMKSenderCertificate *senderCertificate = [self.udManager getSenderCertificate]; From 76f40197c3ee5c7da952b66c5398700c720365f7 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 28 Feb 2020 09:59:37 +0700 Subject: [PATCH 8/8] Update Pods --- Pods | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pods b/Pods index 67dbced37..195f31ff3 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 67dbced37481e0011a3df1397ed57711384a4957 +Subproject commit 195f31ff3609b54d858b2d14113b294ca6f7bece