From dafb1469a83d8dec101f362e38618c8074688cf8 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 4 Oct 2019 14:02:41 +1000 Subject: [PATCH] Add documentation --- .../src/Messages/OWSMessageSender.m | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index c4ec3fdb7..cd48e4eb7 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -926,25 +926,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class]; [[LKAPI getDestinationsFor:contactID] .thenOn(OWSDispatch.sendingQueue, ^(NSArray *destinations) { - // Use a best attempt approach for multi device for now - NSArray *slaveDestinations = [destinations filtered:^BOOL(NSObject *object) { - LKDestination *destination = [object as:LKDestination.class]; - return [destination.kind isEqual:@"slave"]; - }]; - for (LKDestination *slaveDestination in slaveDestinations) { - TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:slaveDestination.hexEncodedPublicKey]; - if (thread.isContactFriend || isSilentMessage || (isFriendRequestMessage && contactID == slaveDestination.hexEncodedPublicKey)) { - OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:slaveDestination]; - [self sendMessage:messageSendCopy]; - } else { - OWSMessageSend *friendRequestMessage = [self getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:slaveDestination.hexEncodedPublicKey]; - [self sendMessage:friendRequestMessage]; - } - } + // Get master destination LKDestination *masterDestination = [destinations filtered:^BOOL(NSObject *object) { LKDestination *destination = [object as:LKDestination.class]; return [destination.kind isEqual:@"master"]; }].firstObject; + // Send to master destination if (masterDestination != nil) { TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:masterDestination.hexEncodedPublicKey]; if (thread.isContactFriend || isSilentMessage || (isFriendRequestMessage && contactID == masterDestination.hexEncodedPublicKey)) { @@ -955,6 +942,22 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [self sendMessage:friendRequestMessage]; } } + // Get slave destinations + NSArray *slaveDestinations = [destinations filtered:^BOOL(NSObject *object) { + LKDestination *destination = [object as:LKDestination.class]; + return [destination.kind isEqual:@"slave"]; + }]; + // Send to slave destinations (using a best attempt approach (i.e. ignoring the message send result) for now) + for (LKDestination *slaveDestination in slaveDestinations) { + TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:slaveDestination.hexEncodedPublicKey]; + if (thread.isContactFriend || isSilentMessage || (isFriendRequestMessage && contactID == slaveDestination.hexEncodedPublicKey)) { + OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:slaveDestination]; + [self sendMessage:messageSendCopy]; + } else { + OWSMessageSend *friendRequestMessage = [self getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:slaveDestination.hexEncodedPublicKey]; + [self sendMessage:friendRequestMessage]; + } + } }) .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { [self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil];