Skip to content

Commit 3c308e1

Browse files
committed
Refactor online presence logic to improve thread participant detection and display
1 parent af18888 commit 3c308e1

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/static/js/shared-agents.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,31 @@
2020
.sort((a, b) => a.localeCompare(b));
2121

2222
const nowMs = Date.now();
23-
const threadOnlineKeys = Array.from(activeThreadLastSeenMs.entries())
24-
.filter(
25-
([key, lastSeenMs]) =>
26-
onlineAgentKeys.has(key) || nowMs - lastSeenMs <= threadActivityWindowMs
27-
)
28-
.map(([key]) => key);
23+
// All participant keys for the active thread (both online and offline)
24+
const threadAllKeys = Array.from(activeThreadLabelsByKey.keys());
25+
26+
// Determine which of the thread participants are considered online/recent
27+
const threadOnlineKeys = threadAllKeys.filter((key) => {
28+
if (onlineAgentKeys.has(key)) return true;
29+
const lastSeenMs = activeThreadLastSeenMs.get(key);
30+
return typeof lastSeenMs === "number" && nowMs - lastSeenMs <= threadActivityWindowMs;
31+
});
32+
33+
const threadAllAgents = threadAllKeys
34+
.map((key) => String(activeThreadLabelsByKey.get(key) || onlineAgentLabelsByKey.get(key) || key))
35+
.sort((a, b) => a.localeCompare(b));
2936

3037
const threadOnlineAgents = threadOnlineKeys
3138
.map((key) => String(activeThreadLabelsByKey.get(key) || onlineAgentLabelsByKey.get(key) || key))
3239
.sort((a, b) => a.localeCompare(b));
3340

3441
const showingThreadScoped = Boolean(activeThreadId);
35-
const total = showingThreadScoped ? threadOnlineKeys.length : onlineAgentEntries.length;
42+
const total = showingThreadScoped ? threadAllKeys.length : onlineAgentEntries.length;
3643

37-
countEl.textContent = showingThreadScoped ? `Thread online ${total}` : `Online agents ${total}`;
44+
countEl.textContent = showingThreadScoped ? `Thread agents ${total}` : `Online agents ${total}`;
3845

3946
const tooltip = showingThreadScoped
40-
? `Thread online: ${threadOnlineAgents.length ? threadOnlineAgents.join(", ") : "(none)"} | Global online: ${onlineAgents.length ? onlineAgents.join(", ") : "(none)"}`
47+
? `Thread participants: ${threadAllAgents.length ? threadAllAgents.join(", ") : "(none)"} | Thread online: ${threadOnlineAgents.length ? threadOnlineAgents.join(", ") : "(none)"} | Global online: ${onlineAgents.length ? onlineAgents.join(", ") : "(none)"}`
4148
: `Agents: ${onlineAgents.length ? onlineAgents.join(", ") : "(none)"}`;
4249
if (window.AcbTooltip && window.AcbTooltip.setTooltip) {
4350
window.AcbTooltip.setTooltip(badgeEl, tooltip);

0 commit comments

Comments
 (0)