diff --git a/packages/ui/src/components/layout/ContextPanel.tsx b/packages/ui/src/components/layout/ContextPanel.tsx index d45f993d..7e9bbee8 100644 --- a/packages/ui/src/components/layout/ContextPanel.tsx +++ b/packages/ui/src/components/layout/ContextPanel.tsx @@ -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, {