refactor: enhance push notification routing with full payload handling and add socket connection state management

This commit is contained in:
pradeepkumar
2026-04-08 21:24:35 +05:30
parent ca81a73e49
commit 509eae2e88
3 changed files with 118 additions and 9 deletions

View File

@@ -59,8 +59,23 @@ class SocketService {
return;
}
// Already fully connected with the same token — no-op.
if (_socket?.connected == true && _currentToken == token) return;
// A socket already exists for this same token but isn't connected yet
// (either in-flight or temporarily disconnected). Don't dispose and
// recreate — that kills the in-flight attempt and causes a race when
// `connect()` is called twice in quick succession (e.g. once from the
// auth provider on app launch and once from chat_screen's
// ensureConnected() after a notification tap). Just kick it to connect.
if (_socket != null && _currentToken == token) {
_intentionalDisconnect = false;
if (_socket!.connected != true) {
_socket!.connect();
}
return;
}
_currentToken = token;
_intentionalDisconnect = false;