Simplify deviceMessages method

no need for a callback as it's a sync method.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 9fe0ca000a
commit 5ae2717872

@ -236,13 +236,10 @@ dispatch_queue_t sendingQueue() {
if (remainingAttempts > 0) { if (remainingAttempts > 0) {
remainingAttempts -= 1; remainingAttempts -= 1;
[self outgoingMessages:message NSArray<NSDictionary *> *deviceMessages = [self deviceMessages:message forRecipient:recipient inThread:thread];
toRecipient:recipient
inThread:thread TSSubmitMessageRequest *request = [[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId
completion:^(NSArray *messages) { messages:deviceMessages
TSSubmitMessageRequest *request =
[[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId
messages:messages
relay:recipient.relay relay:recipient.relay
timeStamp:message.timestamp]; timeStamp:message.timestamp];
@ -274,8 +271,7 @@ dispatch_queue_t sendingQueue() {
[NSJSONSerialization JSONObjectWithData:responseData options:0 error:&e]; [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&e];
if (e) { if (e) {
DDLogError(@"Failed to serialize response of mismatched devices: %@", DDLogError(@"Failed to serialize response of mismatched devices: %@", e.description);
e.description);
} else { } else {
[self handleMismatchedDevices:serializedResponse recipient:recipient]; [self handleMismatchedDevices:serializedResponse recipient:recipient];
} }
@ -323,7 +319,6 @@ dispatch_queue_t sendingQueue() {
break; break;
} }
}]; }];
}];
} else { } else {
[self saveMessage:message withState:TSOutgoingMessageStateUnsent]; [self saveMessage:message withState:TSOutgoingMessageStateUnsent];
BLOCK_SAFE_RUN(failureBlock); BLOCK_SAFE_RUN(failureBlock);
@ -356,10 +351,10 @@ dispatch_queue_t sendingQueue() {
[self saveMessage:message withState:TSOutgoingMessageStateSent]; [self saveMessage:message withState:TSOutgoingMessageStateSent];
} }
- (void)outgoingMessages:(TSOutgoingMessage *)message - (NSArray<NSDictionary *> *)deviceMessages:(TSOutgoingMessage *)message
toRecipient:(SignalRecipient *)recipient forRecipient:(SignalRecipient *)recipient
inThread:(TSThread *)thread inThread:(TSThread *)thread
completion:(messagesQueue)sendMessages { {
NSMutableArray *messagesArray = [NSMutableArray arrayWithCapacity:recipient.devices.count]; NSMutableArray *messagesArray = [NSMutableArray arrayWithCapacity:recipient.devices.count];
TSStorageManager *storage = [TSStorageManager sharedManager]; TSStorageManager *storage = [TSStorageManager sharedManager];
NSData *plainText = [self plainTextForMessage:message inThread:thread]; NSData *plainText = [self plainTextForMessage:message inThread:thread];
@ -381,13 +376,13 @@ dispatch_queue_t sendingQueue() {
if ([exception.name isEqualToString:InvalidDeviceException]) { if ([exception.name isEqualToString:InvalidDeviceException]) {
[recipient removeDevices:[NSSet setWithObject:deviceNumber]]; [recipient removeDevices:[NSSet setWithObject:deviceNumber]];
} else { } else {
DDLogWarn(@"Failed building message for device: %@ withe error %@", deviceNumber, exception);
[self processException:exception outgoingMessage:message inThread:thread]; [self processException:exception outgoingMessage:message inThread:thread];
return;
} }
} }
} }
sendMessages(messagesArray); return [messagesArray copy];
} }
- (NSDictionary *)encryptedMessageWithPlaintext:(NSData *)plainText - (NSDictionary *)encryptedMessageWithPlaintext:(NSData *)plainText

Loading…
Cancel
Save