fix: mark context panel chat sessions as seen

Clears unread state when a chat session is active in the context panel
Keeps embedded chat presence in sync while the window is focused
This commit is contained in:
Bohdan Triapitsyn
2026-06-28 01:05:44 +03:00
parent 1b67aa3c21
commit 00efd8cc4b
@@ -17,6 +17,8 @@ import { useUIStore, type ContextPanelMode } from '@/stores/useUIStore';
import { useInlineCommentDraftStore } from '@/stores/useInlineCommentDraftStore';
import { useSessionUIStore } from '@/sync/session-ui-store';
import { useInputStore } from '@/sync/input-store';
import { markSessionViewed } from '@/sync/notification-store';
import { setExternallyViewedSession } from '@/sync/sync-context';
import { ContextPanelContent } from './ContextSidebarTab';
import { toast } from '@/components/ui';
import { runtimeFetch } from '@/lib/runtime-fetch';
@@ -2176,6 +2178,35 @@ export const ContextPanel: React.FC = () => {
}, [activeTab, directoryKey, setSelectedFilePath]);
const activeChatTabID = activeTab?.mode === 'chat' ? activeTab.id : null;
const activeChatSessionID = activeTab?.mode === 'chat' ? getSessionIDFromDedupeKey(activeTab.dedupeKey) : null;
React.useEffect(() => {
if (!isOpen || !directoryKey || !activeChatSessionID || typeof window === 'undefined') {
return;
}
const markActiveChatViewed = () => {
if (document.visibilityState === 'hidden' || !document.hasFocus()) {
setExternallyViewedSession(directoryKey, activeChatSessionID, false);
return;
}
markSessionViewed(activeChatSessionID);
setExternallyViewedSession(directoryKey, activeChatSessionID, true);
};
markActiveChatViewed();
const interval = window.setInterval(markActiveChatViewed, 10_000);
window.addEventListener('focus', markActiveChatViewed);
document.addEventListener('visibilitychange', markActiveChatViewed);
return () => {
window.clearInterval(interval);
window.removeEventListener('focus', markActiveChatViewed);
document.removeEventListener('visibilitychange', markActiveChatViewed);
setExternallyViewedSession(directoryKey, activeChatSessionID, false);
};
}, [activeChatSessionID, directoryKey, isOpen]);
const getEmbeddedChatSrc = React.useCallback((tabID: string, sessionID: string, readOnly: boolean): string => {
return getOrCreateEmbeddedSessionChatURL(chatFrameSrcByTabIDRef.current, tabID, sessionID, directoryKey || null, readOnly, {