fixed a race condition in long-poll initialization by adding a token validation guard to prevent stale chat sessions from hijacking the current state during navigation or app resumes.

This commit is contained in:
2026-07-05 23:55:01 +02:00
parent dab208877f
commit 5952c6619f
@@ -196,6 +196,13 @@ class ChatBloc
void _startLongPoll(String token) {
if (!_appResumed) return;
// A load chain may finish AFTER the user already switched chats — e.g. a
// notification tap resumes the app (lifecycle refresh starts loading the
// still-open chat A) and then navigates to chat B. Without this guard the
// stale chain's completion would hijack the long-poll back to A and its
// responses would merge A's messages into B's state (chat B showing chat
// A's content) while B never receives live updates.
if ((innerState?.currentToken ?? '') != token) return;
if (_pollingToken == token) return;
_stopLongPoll();
_pollingToken = token;