Fix chat unread: don't mark unread if user viewed the streaming response#134
Fix chat unread: don't mark unread if user viewed the streaming response#134mcintyre94 wants to merge 1 commit into
Conversation
Add hasSeenCurrentTurnResponse tracking to ChatViewModel so that a false-unread is not triggered when isActive briefly drops to false at the exact moment the result event fires (e.g. view lifecycle timing during a NavigationStack transition). The flag is set via didSet observers on both `status` (when transitioning to .streaming while isActive) and `isActive` (when the user opens a chat already in .streaming). It is reset at the start of each new user turn (sendMessage) and each reconnect (reconnectIfNeeded). markChatUnread now guards on !isActive && !hasSeenCurrentTurnResponse, satisfying both "chat is not open" and "user genuinely hasn't seen this response" before setting the unread indicator. Adds 6 unit tests covering the key scenarios. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Code reviewOne issue found:
The reset on line 840 is not reached when Concrete scenario where chat is incorrectly not marked unread:
The same issue applies to the Suggested fix: Reset |
Summary
hasSeenCurrentTurnResponseflag toChatViewModelto track whether the user was actively viewing a turn while it streamedmarkChatUnreadto guard on both!isActiveand!hasSeenCurrentTurnResponse, fixing a race whereisActivebriefly drops tofalseat the exact moment the result event fires (e.g. during aNavigationStackview lifecycle transition)sendMessage) and each reconnect (reconnectIfNeeded)Test plan
.connectingalone doesn't set the seen flag,.connecting→.streamingtransition does set it🤖 Generated with Claude Code