Add documentation

pull/56/head
Niels Andriesse 6 years ago
parent 8c3a5f6bd8
commit dafb1469a8

@ -926,25 +926,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class]; BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class];
[[LKAPI getDestinationsFor:contactID] [[LKAPI getDestinationsFor:contactID]
.thenOn(OWSDispatch.sendingQueue, ^(NSArray<LKDestination *> *destinations) { .thenOn(OWSDispatch.sendingQueue, ^(NSArray<LKDestination *> *destinations) {
// Use a best attempt approach for multi device for now // Get master destination
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];
}
}
LKDestination *masterDestination = [destinations filtered:^BOOL(NSObject *object) { LKDestination *masterDestination = [destinations filtered:^BOOL(NSObject *object) {
LKDestination *destination = [object as:LKDestination.class]; LKDestination *destination = [object as:LKDestination.class];
return [destination.kind isEqual:@"master"]; return [destination.kind isEqual:@"master"];
}].firstObject; }].firstObject;
// Send to master destination
if (masterDestination != nil) { if (masterDestination != nil) {
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:masterDestination.hexEncodedPublicKey]; TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:masterDestination.hexEncodedPublicKey];
if (thread.isContactFriend || isSilentMessage || (isFriendRequestMessage && contactID == masterDestination.hexEncodedPublicKey)) { if (thread.isContactFriend || isSilentMessage || (isFriendRequestMessage && contactID == masterDestination.hexEncodedPublicKey)) {
@ -955,6 +942,22 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[self sendMessage:friendRequestMessage]; [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) { .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {
[self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil]; [self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil];

Loading…
Cancel
Save