From 6949c56c17dd9490da337c4b40be8c4428f4a1f7 Mon Sep 17 00:00:00 2001 From: Clay Date: Thu, 3 Dec 2026 15:00:25 -0500 Subject: [PATCH] Add tab close buttons: leave chat rooms, close PMs --- HANDOFF.md | 2 +- public/app.js | 27 +++++++++++++++++++++------ public/index.html | 4 ++-- public/js/ui.js | 26 +++++++++++++++++++++----- public/style.css | 46 +++++++++++++++++++++++++++++++++------------- 5 files changed, 78 insertions(+), 27 deletions(-) diff --git a/HANDOFF.md b/HANDOFF.md index 81816ba..519ef72 100644 --- a/HANDOFF.md +++ b/HANDOFF.md @@ -101,7 +101,7 @@ Against local open-oscar-server 0.25.0 with `DISABLE_AUTH=true`, TOC listener 98 ## Needs to be done next 1. **Deploy publicly behind HTTPS nginx:** `LISTEN_HOST=127.0.0.1`, `TRUST_PROXY=1`, `COOKIE_SECURE=true`, strong `SESSION_SECRET`, `.env` chmod `0600`, non-root systemd service, firewall block app port, nginx SSE buffering off for `/api/events`. -2. **UI polish follow-up:** tab close buttons, unread indicators, chat room membership/leave/invite-send UI, better mobile layout. +2. **UI polish follow-up:** unread indicators, chat room membership/invite-send UI, better mobile layout. (Tab close/leave for PMs and chat rooms added 2026-12-03.) 3. **Harden TOC client:** handle reconnect/backoff, keepalive timeout, parse CONFIG2 buddy list properly, handle TOC1/TOC2 variants, handle chat errors/room not found. 4. **Chat UX:** show chat room membership, leave button, invite-send UI, better system messages, error states. 5. **Security follow-up:** configurable login host/ports enable arbitrary server targets; consider SSRF/egress restrictions or allowlist if exposed publicly. diff --git a/public/app.js b/public/app.js index ad305a8..d9b393c 100644 --- a/public/app.js +++ b/public/app.js @@ -1,7 +1,7 @@ // public/app.js - front-end entry point. Wires state, UI, API, and event stream. -import { api } from './js/api.js'; -import { createStream } from './js/stream.js'; -import * as ui from './js/ui.js'; +import { api } from './js/api.js?v=32'; +import { createStream } from './js/stream.js?v=32'; +import * as ui from './js/ui.js?v=32'; window.addEventListener('error', (e) => { console.error('[ui] error', e.error || e.message); @@ -20,7 +20,7 @@ const state = { invites: [], // { roomId, roomName, from, message, time } selectConversation(key) { state.active = key; - ui.renderConversations(state); + ui.renderConversations(state, closeConversation); ui.renderMessages(state); }, }; @@ -49,7 +49,7 @@ function addMessage(type, name, msg) { if (msg?.text && conv.messages.slice(-6).some((m) => m.text === msg.text && normalizeName(m.from) === normalizeName(msg.from) && !!m.mine === !!msg.mine)) return; conv.messages.push(msg); if (!state.active) state.active = conv.key; - ui.renderConversations(state); + ui.renderConversations(state, closeConversation); ui.renderMessages(state); } @@ -65,6 +65,21 @@ function openChat(name) { state.selectConversation(conv.key); } +async function closeConversation(key) { + const conv = state.conversations[key]; + if (!conv) return; + if (conv.type === 'chat') { + try { await api.leaveRoom(conv.roomId || conv.name); } catch (err) { console.warn('[chat] leave failed', err.message); } + } + delete state.conversations[key]; + if (state.active === key) { + const keys = Object.keys(state.conversations); + state.active = keys[keys.length - 1] || null; + } + ui.renderConversations(state, closeConversation); + ui.renderMessages(state); +} + function plainText(s) { if (typeof s !== 'string') return ''; // AIM messages often arrive as HTML; render as plain text safely. @@ -460,7 +475,7 @@ async function afterLogin(screenName) { ui.showChat(screenName); ui.setMessageStyle(ui.getMessageStyle()); ui.setTocStatus(false); - ui.renderConversations(state); + ui.renderConversations(state, closeConversation); ui.renderMessages(state); stream.connect(); await loadBuddies(); diff --git a/public/index.html b/public/index.html index b035787..22a2718 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ Web OSCAR Chat - +
@@ -98,6 +98,6 @@
- + diff --git a/public/js/ui.js b/public/js/ui.js index e346f40..41aa940 100644 --- a/public/js/ui.js +++ b/public/js/ui.js @@ -82,15 +82,31 @@ export function showBroadcast(text) { banner.classList.remove('hidden'); } -export function renderConversations(state) { +export function renderConversations(state, onClose) { const list = el('conversations'); clear(list); for (const conv of Object.values(state.conversations)) { const li = document.createElement('li'); - const label = conv.type === 'chat' ? `# ${conv.name}` : conv.name; - li.appendChild(button(label, () => state.selectConversation(conv.key), { - active: state.active === conv.key, - })); + li.className = 'tab' + (state.active === conv.key ? ' active' : ''); + + const labelBtn = document.createElement('button'); + labelBtn.type = 'button'; + labelBtn.className = 'tab-label'; + labelBtn.textContent = conv.type === 'chat' ? `# ${conv.name}` : conv.name; + labelBtn.title = conv.type === 'chat' ? `Chat: ${conv.name}` : `IM: ${conv.name}`; + labelBtn.addEventListener('click', () => state.selectConversation(conv.key)); + + const closeBtn = document.createElement('button'); + closeBtn.type = 'button'; + closeBtn.className = 'tab-close'; + closeBtn.textContent = '×'; + closeBtn.title = conv.type === 'chat' ? 'Leave/close chat' : 'Close conversation'; + closeBtn.addEventListener('click', (e) => { + e.stopPropagation(); + if (typeof onClose === 'function') onClose(conv.key); + }); + + li.append(labelBtn, closeBtn); list.appendChild(li); } } diff --git a/public/style.css b/public/style.css index 08b6458..02054e4 100644 --- a/public/style.css +++ b/public/style.css @@ -155,29 +155,49 @@ main { padding: 1rem; max-width: 1600px; margin: 0 auto; } gap: 0.35rem; min-width: max-content; } -.tabs li { margin: 0; } -.tabs button { +.tabs li.tab { + margin: 0; + display: inline-flex; + align-items: stretch; background: #1a1f29; - color: var(--muted); border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; - padding: 0.5rem 0.75rem; - font-weight: 500; - max-width: 220px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; + max-width: 260px; } -.tabs button:hover { color: var(--text); background: #232a36; border-color: #4a5568; } -.tabs button.active { - color: var(--text); +.tabs li.tab:hover { background: #232a36; border-color: #4a5568; } +.tabs li.tab.active { background: var(--panel); border: 2px solid var(--accent); border-bottom: 1px solid var(--panel); margin-bottom: -1px; - font-weight: 600; } +.tabs .tab-label, +.tabs .tab-close { + background: transparent; + color: var(--muted); + border: 0; + border-radius: 0; + padding: 0.45rem 0.6rem; + font-weight: 500; +} +.tabs .tab-label { + max-width: 200px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + padding-right: 0.2rem; +} +.tabs .tab-close { + padding-left: 0.25rem; + padding-right: 0.55rem; + color: #8090a5; + font-size: 1rem; + line-height: 1; +} +.tabs .tab-close:hover { color: #ff8b8b; background: rgba(255,107,107,0.08); } +.tabs li.tab.active .tab-label { color: var(--text); font-weight: 600; } +.tabs li.tab:hover .tab-label { color: var(--text); } .chat-header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 1rem; align-items: center; } .chat-header h2 { margin: 0; font-size: 1rem; }