Merge branch 'mkirk/fix-initial-contact-group-sync' into hotfix/2.27.1

pull/1/head
Michael Kirk 7 years ago
commit 6a502fcec4

@ -625,11 +625,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
[self sendMessageToService:message [self sendMessageToService:message
recipient:recipient recipient:recipient
thread:thread thread:thread
attempts:OWSMessageSenderRetryAttempts attempts:OWSMessageSenderRetryAttempts
success:successHandler useWebsocketIfAvailable:YES
failure:failureHandler]; success:successHandler
failure:failureHandler];
} else { } else {
// Neither a group nor contact thread? This should never happen. // Neither a group nor contact thread? This should never happen.
OWSFail(@"%@ Unknown message type: %@", self.logTag, NSStringFromClass([message class])); OWSFail(@"%@ Unknown message type: %@", self.logTag, NSStringFromClass([message class]));
@ -652,6 +653,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
recipient:recipient recipient:recipient
thread:thread thread:thread
attempts:OWSMessageSenderRetryAttempts attempts:OWSMessageSenderRetryAttempts
useWebsocketIfAvailable:YES
success:^{ success:^{
[futureSource trySetResult:@1]; [futureSource trySetResult:@1];
} }
@ -772,7 +774,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (void)sendMessageToService:(TSOutgoingMessage *)message - (void)sendMessageToService:(TSOutgoingMessage *)message
recipient:(SignalRecipient *)recipient recipient:(SignalRecipient *)recipient
thread:(nullable TSThread *)thread thread:(nullable TSThread *)thread
attempts:(int)remainingAttempts attempts:(int)remainingAttemptsParam
useWebsocketIfAvailable:(BOOL)useWebsocketIfAvailable
success:(void (^)(void))successHandler success:(void (^)(void))successHandler
failure:(RetryableFailureHandler)failureHandler failure:(RetryableFailureHandler)failureHandler
{ {
@ -806,7 +809,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return failureHandler(error); return failureHandler(error);
} }
if (remainingAttempts <= 0) { if (remainingAttemptsParam <= 0) {
// We should always fail with a specific error. // We should always fail with a specific error.
OWSProdFail([OWSAnalyticsEvents messageSenderErrorGenericSendFailure]); OWSProdFail([OWSAnalyticsEvents messageSenderErrorGenericSendFailure]);
@ -814,7 +817,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[error setIsRetryable:YES]; [error setIsRetryable:YES];
return failureHandler(error); return failureHandler(error);
} }
remainingAttempts -= 1; int remainingAttempts = remainingAttemptsParam - 1;
NSArray<NSDictionary *> *deviceMessages; NSArray<NSDictionary *> *deviceMessages;
@try { @try {
@ -946,15 +949,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}); });
return; return;
} else if (mayHaveLinkedDevices) { } else if (mayHaveLinkedDevices && !hasDeviceMessages) {
// We may have just linked a new secondary device which is not yet reflected in // We may have just linked a new secondary device which is not yet reflected in
// the SignalRecipient that corresponds to ourself. Proceed. Client should learn // the SignalRecipient that corresponds to ourself. Proceed. Client should learn
// of new secondary devices via 409 "Mismatched devices" response. // of new secondary devices via 409 "Mismatched devices" response.
DDLogWarn(@"%@ sync message has no device messages but account has secondary devices.", self.logTag); DDLogWarn(@"%@ account has secondary devices, but sync message has no device messages", self.logTag);
} else if (hasDeviceMessages) { } else if (!mayHaveLinkedDevices && hasDeviceMessages) {
OWSFail(@"%@ sync message has device messages for unknown secondary devices.", self.logTag); OWSFail(@"%@ sync message has device messages for unknown secondary devices.", self.logTag);
} else {
// Account has secondary devices; proceed as usual.
} }
} else { } else {
OWSAssert(deviceMessages.count > 0); OWSAssert(deviceMessages.count > 0);
@ -978,7 +979,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messages:deviceMessages messages:deviceMessages
relay:recipient.relay relay:recipient.relay
timeStamp:message.timestamp]; timeStamp:message.timestamp];
if (TSSocketManager.canMakeRequests) { if (useWebsocketIfAvailable && TSSocketManager.canMakeRequests) {
[TSSocketManager.sharedManager makeRequest:request [TSSocketManager.sharedManager makeRequest:request
success:^(id _Nullable responseObject) { success:^(id _Nullable responseObject) {
[self messageSendDidSucceed:message [self messageSendDidSucceed:message
@ -988,19 +989,21 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
success:successHandler]; success:successHandler];
} }
failure:^(NSInteger statusCode, NSData *_Nullable responseData, NSError *error) { failure:^(NSInteger statusCode, NSData *_Nullable responseData, NSError *error) {
[self messageSendDidFail:message // Websockets can fail in different ways, so we don't decrement remainingAttempts for websocket failure.
recipient:recipient // Instead we fall back to REST, which will decrement retries.
thread:thread // e.g. after linking a new device, sync messages will fail until the websocket re-opens.
isLocalNumber:isLocalNumber [self sendMessageToService:message
deviceMessages:deviceMessages recipient:recipient
remainingAttempts:remainingAttempts thread:thread
statusCode:statusCode attempts:remainingAttemptsParam
error:error useWebsocketIfAvailable:NO
responseData:responseData success:successHandler
success:successHandler failure:failureHandler];
failure:failureHandler];
}]; }];
} else { } else {
if (!useWebsocketIfAvailable && TSSocketManager.canMakeRequests) {
DDLogDebug(@"%@ in %s falling back to REST since first attempt failed.", self.logTag, __PRETTY_FUNCTION__);
}
[self.networkManager makeRequest:request [self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) { success:^(NSURLSessionDataTask *task, id responseObject) {
[self messageSendDidSucceed:message [self messageSendDidSucceed:message
@ -1098,11 +1101,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
dispatch_async([OWSDispatch sendingQueue], ^{ dispatch_async([OWSDispatch sendingQueue], ^{
DDLogDebug(@"%@ Retrying: %@", self.logTag, message.debugDescription); DDLogDebug(@"%@ Retrying: %@", self.logTag, message.debugDescription);
[self sendMessageToService:message [self sendMessageToService:message
recipient:recipient recipient:recipient
thread:thread thread:thread
attempts:remainingAttempts attempts:remainingAttempts
success:successHandler useWebsocketIfAvailable:NO
failure:failureHandler]; success:successHandler
failure:failureHandler];
}); });
}; };
@ -1250,6 +1254,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
recipient:[SignalRecipient selfRecipient] recipient:[SignalRecipient selfRecipient]
thread:message.thread thread:message.thread
attempts:OWSMessageSenderRetryAttempts attempts:OWSMessageSenderRetryAttempts
useWebsocketIfAvailable:YES
success:^{ success:^{
DDLogInfo(@"Successfully sent sync transcript."); DDLogInfo(@"Successfully sent sync transcript.");
} }

Loading…
Cancel
Save