From c4dcb5f80759272961022e028860da410a1d06df Mon Sep 17 00:00:00 2001 From: Lilia Date: Fri, 23 Oct 2015 02:36:48 -0700 Subject: [PATCH] Fixes #907 Upon receiving a 404 to a prekey request for a particular device D, the client handles that error by removing device D from the recipient's device list, and proceeds to encrypt and send to the remaining known devices. Reviewed & Patched by @FredericJacobs --- .../Messages/TSMessagesManager+sendMessages.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Signal/src/textsecure/Messages/TSMessagesManager+sendMessages.m b/Signal/src/textsecure/Messages/TSMessagesManager+sendMessages.m index 10edd78c9..c582f70ee 100644 --- a/Signal/src/textsecure/Messages/TSMessagesManager+sendMessages.m +++ b/Signal/src/textsecure/Messages/TSMessagesManager+sendMessages.m @@ -29,6 +29,8 @@ #define RETRY_ATTEMPTS 3 +#define InvalidDeviceException @"InvalidDeviceException" + @interface TSMessagesManager () dispatch_queue_t sendingQueue(void); @end @@ -274,8 +276,12 @@ dispatch_queue_t sendingQueue() { } } @catch (NSException *exception) { - [self processException:exception outgoingMessage:message inThread:thread]; - return; + if ([exception.name isEqualToString:InvalidDeviceException]){ + [recipient removeDevices:[NSSet setWithObject:deviceNumber]]; + } else { + [self processException:exception outgoingMessage:message inThread:thread]; + return; + } } } @@ -293,6 +299,10 @@ dispatch_queue_t sendingQueue() { dispatch_semaphore_signal(sema); } failure:^(NSURLSessionDataTask *task, NSError *error) { DDLogError(@"Server replied on PreKeyBundle request with error: %@", error); + NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; + if (response.statusCode == 404) { + @throw [NSException exceptionWithName:InvalidDeviceException reason:@"Device not registered" userInfo:nil]; + } dispatch_semaphore_signal(sema); }]; dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);