diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index d473b0ef2..ad681ebd4 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -239,7 +239,8 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); // Ensure that the success and failure blocks are called on the main thread. void (^failureBlock)(NSError *) = ^(NSError *error) { OWSLogError(@"Updating service with profile failed."); - + + /* // We use a "self-only" contact sync to indicate to desktop // that we've changed our profile and that it should do a // profile fetch for "self". @@ -249,6 +250,10 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); if (requiresSync) { [[self.syncManager syncLocalContact] retainUntilComplete]; } + */ + if (requiresSync) { + [LKSyncMessagesProtocol syncProfileUpdate]; + } dispatch_async(dispatch_get_main_queue(), ^{ failureBlockParameter(error); @@ -256,13 +261,18 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); }; void (^successBlock)(void) = ^{ OWSLogInfo(@"Successfully updated service with profile."); - + + /* // We use a "self-only" contact sync to indicate to desktop // that we've changed our profile and that it should do a // profile fetch for "self". if (requiresSync) { [[self.syncManager syncLocalContact] retainUntilComplete]; } + */ + if (requiresSync) { + [LKSyncMessagesProtocol syncProfileUpdate]; + } dispatch_async(dispatch_get_main_queue(), ^{ successBlockParameter(); diff --git a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift index 5574c8463..b500a6cfa 100644 --- a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift @@ -23,6 +23,22 @@ public final class SyncMessagesProtocol : NSObject { // FIXME: We added this check to avoid a crash, but we should really figure out why that crash was happening in the first place return !UserDefaults.standard[.hasLaunchedOnce] } + + @objc(syncProfileUpdate) + public static func syncProfileUpdate() { + storage.dbReadWriteConnection.readWrite{ transaction in + let userHexEncodedPublicKey = getUserHexEncodedPublicKey() + let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: userHexEncodedPublicKey, in: transaction) + for hexEncodedPublicKey in linkedDevices { + guard hexEncodedPublicKey != userHexEncodedPublicKey else { continue } + let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) + let syncMessage = OWSOutgoingSyncMessage.init(in: thread, messageBody: "", attachmentId: nil) + syncMessage.save(with: transaction) + let messageSenderJobQueue = SSKEnvironment.shared.messageSenderJobQueue + messageSenderJobQueue.add(message: syncMessage, transaction: transaction) + } + } + } @objc(syncContactWithHexEncodedPublicKey:in:) public static func syncContact(_ hexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> AnyPromise { @@ -166,9 +182,10 @@ public final class SyncMessagesProtocol : NSObject { let parser = ContactParser(data: data) let hexEncodedPublicKeys = parser.parseHexEncodedPublicKeys() let userHexEncodedPublicKey = getUserHexEncodedPublicKey() + let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: userHexEncodedPublicKey, in: transaction) // Try to establish sessions for hexEncodedPublicKey in hexEncodedPublicKeys { - guard hexEncodedPublicKey != userHexEncodedPublicKey else { continue } // Skip self + guard !linkedDevices.contains(hexEncodedPublicKey) else { continue } // Skip self and linked devices // We don't update the friend request status; that's done in OWSMessageSender.sendMessage(_:) let friendRequestStatus = storage.getFriendRequestStatus(for: hexEncodedPublicKey, transaction: transaction) switch friendRequestStatus { diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 90e5d6929..3bdab9362 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -1125,21 +1125,23 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt } - (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient { - return SSKProtoContent.builder; -} - -- (nullable NSData *)buildPlainTextData:(SignalRecipient *)recipient -{ - NSError *error; SSKProtoDataMessage *_Nullable dataMessage = [self buildDataMessage:recipient.recipientId]; - if (error || !dataMessage) { - OWSFailDebug(@"could not build protobuf: %@", error); + if (!dataMessage) { + OWSFailDebug(@"could not build protobuf"); return nil; } + + SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder; + [contentBuilder setDataMessage:dataMessage]; + + return contentBuilder; +} +- (nullable NSData *)buildPlainTextData:(SignalRecipient *)recipient +{ SSKProtoContentBuilder *contentBuilder = [self prepareCustomContentBuilder:recipient]; + NSError *error; - [contentBuilder setDataMessage:dataMessage]; NSData *_Nullable contentData = [contentBuilder buildSerializedDataAndReturnError:&error]; if (error || !contentData) { OWSFailDebug(@"could not serialize protobuf: %@", error);