Handle presence updates for buddy status dots

This commit is contained in:
Clay 2026-12-03 14:22:43 -05:00
parent 4e2676433f
commit d4dfdd0326
3 changed files with 22 additions and 3 deletions

View file

@ -243,6 +243,23 @@ stream.on('buddylist', (event) => {
ui.renderBuddies(state.buddies, (name) => openIM(name));
});
stream.on('presence', (event) => {
const d = event.data || event.raw?.eventData || {};
const name = String(d.screenName || d.aimId || d.displayId || d.name || '');
if (!name) return;
const norm = normalizeName(name);
let found = false;
state.buddies = (state.buddies || []).map((b) => {
const bName = typeof b === 'string' ? b : (b.aimId || b.displayId || b.screenName || b.name || '');
if (normalizeName(bName) !== norm) return b;
found = true;
const base = typeof b === 'string' ? { screenName: b } : { ...b };
return { ...base, ...d, screenName: base.screenName || name };
});
if (!found) state.buddies.push({ screenName: name, ...d });
ui.renderBuddies(state.buddies, (n) => openIM(n));
});
stream.on('broadcast', (event) => {
const d = event.data || event.raw?.eventData || {};
const text = event.text || d.message || d.text || d.msg || '';

View file

@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web OSCAR Chat</title>
<link rel="stylesheet" href="/style.css?v=25">
<link rel="stylesheet" href="/style.css?v=26">
</head>
<body>
<div id="app">
@ -86,6 +86,6 @@
</main>
</div>
<script type="module" src="/app.js?v=25"></script>
<script type="module" src="/app.js?v=26"></script>
</body>
</html>

View file

@ -149,8 +149,10 @@ export function renderUserResults(users, onOpen) {
function buddyStatus(b) {
const raw = String(b?.state || b?.status || '').toLowerCase();
if (['online', 'present', 'active'].includes(raw)) return 'online';
if (['away', 'idle', 'dnd', 'busy', 'na'].includes(raw) || b?.idleMins > 0) return 'away';
if (['away', 'idle', 'dnd', 'busy', 'na'].includes(raw) || Number(b?.idleMins) > 0) return 'away';
if (['offline', 'disconnected'].includes(raw)) return 'offline';
if (b?.online === true || b?.online === 'true' || b?.online === 1) return 'online';
if (b?.online === false || b?.online === 'false' || b?.online === 0) return 'offline';
// If we have an object but no explicit state, default to offline/unknown.
if (b && typeof b === 'object' && !raw) return 'offline';
return raw ? 'away' : 'offline';