diff --git a/muxplex/frontend/app.js b/muxplex/frontend/app.js index 5780f3a..f5b3a0a 100644 --- a/muxplex/frontend/app.js +++ b/muxplex/frontend/app.js @@ -1039,8 +1039,9 @@ function showToast(msg) { function updatePillBell() { const el = $('session-pill-bell'); if (!el) return; + const viewingKey = _viewingRemoteId ? (_viewingRemoteId + ':' + _viewingSession) : _viewingSession; const hasBell = _currentSessions.some( - (s) => s.name !== _viewingSession && s.bell && s.bell.unseen_count > 0, + (s) => (s.sessionKey || s.name) !== viewingKey && s.bell && s.bell.unseen_count > 0, ); if (hasBell) el.classList.remove('hidden'); else el.classList.add('hidden'); } @@ -1872,8 +1873,9 @@ function updateSessionPill(sessions) { if (_viewMode !== 'fullscreen') return; var pillBell = $('session-pill-bell'); if (!pillBell) return; + var viewingKey = _viewingRemoteId ? (_viewingRemoteId + ':' + _viewingSession) : _viewingSession; var othersWithBell = sessions.filter(function(s) { - return s.name !== _viewingSession && + return (s.sessionKey || s.name) !== viewingKey && s.bell && s.bell.unseen_count > 0 && (s.bell.seen_at === null || s.bell.last_fired_at > s.bell.seen_at); }); diff --git a/muxplex/tests/test_frontend_js.py b/muxplex/tests/test_frontend_js.py index e4dbe38..e937725 100644 --- a/muxplex/tests/test_frontend_js.py +++ b/muxplex/tests/test_frontend_js.py @@ -2494,3 +2494,52 @@ def test_device_name_change_updates_document_title() -> None: assert "document.title" in body, ( "bindStaticEventListeners device-name handler must update document.title" ) + + +# ─── task-4-frontend-session-key-comparison ───────────────────────────────── + + +def test_update_pill_bell_uses_session_key_or_name() -> None: + """updatePillBell must compare using sessionKey||name against a viewingKey + that accounts for remote sessions (_viewingRemoteId prefix).""" + match = re.search( + r"function updatePillBell\s*\(\s*\)\s*\{(.*?)\n\}", + _JS, + re.DOTALL, + ) + assert match, "updatePillBell function not found" + body = match.group(1) + # Must build viewingKey using _viewingRemoteId + assert "_viewingRemoteId" in body, ( + "updatePillBell must reference _viewingRemoteId to build viewingKey" + ) + assert "viewingKey" in body, ( + "updatePillBell must define a viewingKey variable" + ) + # Must compare using sessionKey || s.name (not just s.name) + assert "sessionKey" in body, ( + "updatePillBell must compare using s.sessionKey || s.name (not just s.name)" + ) + + +def test_update_session_pill_uses_session_key_or_name() -> None: + """updateSessionPill must compare using sessionKey||name against a viewingKey + that accounts for remote sessions (_viewingRemoteId prefix).""" + match = re.search( + r"function updateSessionPill\s*\(\w+\)\s*\{(.*?)\n\}", + _JS, + re.DOTALL, + ) + assert match, "updateSessionPill function not found" + body = match.group(1) + # Must build viewingKey using _viewingRemoteId + assert "_viewingRemoteId" in body, ( + "updateSessionPill must reference _viewingRemoteId to build viewingKey" + ) + assert "viewingKey" in body, ( + "updateSessionPill must define a viewingKey variable" + ) + # Must compare using sessionKey || s.name (not just s.name) + assert "sessionKey" in body, ( + "updateSessionPill must compare using s.sessionKey || s.name (not just s.name)" + )