diff --git a/src/Account/TSAccountManager.h b/src/Account/TSAccountManager.h index 5a8e85723..f984ce173 100644 --- a/src/Account/TSAccountManager.h +++ b/src/Account/TSAccountManager.h @@ -34,7 +34,7 @@ static NSString *const TSRegistrationErrorUserInfoHTTPStatus = @"TSHTTPStatus"; - (void)ifRegistered:(BOOL)isRegistered runAsync:(void (^)())block; /** - * Returns registered number + * Returns current phone number for this device, which may not yet have been registered. * * @return E164 formatted phone number */ diff --git a/src/Account/TSAccountManager.m b/src/Account/TSAccountManager.m index 8ef0bed4b..e4ea3d9b7 100644 --- a/src/Account/TSAccountManager.m +++ b/src/Account/TSAccountManager.m @@ -18,7 +18,6 @@ #import "TSSocketManager.h" #import "TSStorageManager+keyingMaterial.h" - NS_ASSUME_NONNULL_BEGIN @interface TSAccountManager () @@ -139,6 +138,9 @@ NS_ASSUME_NONNULL_BEGIN return; } + // The country code of TSAccountManager.phoneNumberAwaitingVerification is used to + // determine whether or not to use domain fronting, so it needs to be set _before_ + // we make our verification code request. TSAccountManager *manager = [self sharedInstance]; manager.phoneNumberAwaitingVerification = phoneNumber; diff --git a/src/Network/WebSockets/TSSocketManager.m b/src/Network/WebSockets/TSSocketManager.m index 7cdb41d6f..b1397789f 100644 --- a/src/Network/WebSockets/TSSocketManager.m +++ b/src/Network/WebSockets/TSSocketManager.m @@ -92,6 +92,7 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification"; return; } + // Try to reuse the existing socket (if any) if it is in a valid state. SRWebSocket *socket = self.websocket; if (socket) { switch ([socket readyState]) { @@ -104,14 +105,16 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification"; self.status = kSocketStatusConnecting; return; default: - [socket close]; - self.status = kSocketStatusClosed; - socket.delegate = nil; - socket = nil; break; } } + // Discard the old socket which is already closed or is closing. + [socket close]; + self.status = kSocketStatusClosed; + socket.delegate = nil; + + // Create a new web socket. NSString *webSocketConnect = [textSecureWebSocketAPI stringByAppendingString:[self webSocketAuthenticationString]]; NSURL *webSocketConnectURL = [NSURL URLWithString:webSocketConnect]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:webSocketConnectURL];