diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m index 0405ef4f1..4e0b008ba 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m @@ -169,6 +169,10 @@ NS_ASSUME_NONNULL_BEGIN dispatch_async(dispatch_get_main_queue(), ^{ [self.linkedDevicesTableViewController expectMoreDevices]; [self.navigationController popToViewController:self.linkedDevicesTableViewController animated:YES]; + + // The service implementation of the socket connection caches the linked device state, + // so all sync message sends will fail on the socket until it is cycled. + [TSSocketManager.sharedManager cycleSocket]; }); } failure:^(NSError *error) { diff --git a/SignalServiceKit/src/Network/WebSockets/TSSocketManager.h b/SignalServiceKit/src/Network/WebSockets/TSSocketManager.h index 80a72f7fd..942a7335e 100644 --- a/SignalServiceKit/src/Network/WebSockets/TSSocketManager.h +++ b/SignalServiceKit/src/Network/WebSockets/TSSocketManager.h @@ -41,6 +41,9 @@ typedef void (^TSSocketMessageFailure)(NSInteger statusCode, NSData *_Nullable r // This method can be called from any thread. + (void)requestSocketOpen; +// This can be used to force the socket to close and re-open, if it is open. +- (void)cycleSocket; + #pragma mark - Message Sending + (BOOL)canMakeRequests; diff --git a/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m b/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m index 63eab3066..c3310d130 100644 --- a/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m +++ b/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m @@ -800,6 +800,15 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_ } } +- (void)cycleSocket +{ + OWSAssertIsOnMainThread(); + + [self closeWebSocket]; + + [self applyDesiredSocketState]; +} + - (void)handleSocketFailure { OWSAssertIsOnMainThread();