Add tab close buttons: leave chat rooms, close PMs
This commit is contained in:
parent
e1ec81081e
commit
6949c56c17
5 changed files with 78 additions and 27 deletions
|
|
@ -101,7 +101,7 @@ Against local open-oscar-server 0.25.0 with `DISABLE_AUTH=true`, TOC listener 98
|
||||||
## Needs to be done next
|
## 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`.
|
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.
|
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.
|
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.
|
5. **Security follow-up:** configurable login host/ports enable arbitrary server targets; consider SSRF/egress restrictions or allowlist if exposed publicly.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// public/app.js - front-end entry point. Wires state, UI, API, and event stream.
|
// public/app.js - front-end entry point. Wires state, UI, API, and event stream.
|
||||||
import { api } from './js/api.js';
|
import { api } from './js/api.js?v=32';
|
||||||
import { createStream } from './js/stream.js';
|
import { createStream } from './js/stream.js?v=32';
|
||||||
import * as ui from './js/ui.js';
|
import * as ui from './js/ui.js?v=32';
|
||||||
|
|
||||||
window.addEventListener('error', (e) => {
|
window.addEventListener('error', (e) => {
|
||||||
console.error('[ui] error', e.error || e.message);
|
console.error('[ui] error', e.error || e.message);
|
||||||
|
|
@ -20,7 +20,7 @@ const state = {
|
||||||
invites: [], // { roomId, roomName, from, message, time }
|
invites: [], // { roomId, roomName, from, message, time }
|
||||||
selectConversation(key) {
|
selectConversation(key) {
|
||||||
state.active = key;
|
state.active = key;
|
||||||
ui.renderConversations(state);
|
ui.renderConversations(state, closeConversation);
|
||||||
ui.renderMessages(state);
|
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;
|
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);
|
conv.messages.push(msg);
|
||||||
if (!state.active) state.active = conv.key;
|
if (!state.active) state.active = conv.key;
|
||||||
ui.renderConversations(state);
|
ui.renderConversations(state, closeConversation);
|
||||||
ui.renderMessages(state);
|
ui.renderMessages(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,6 +65,21 @@ function openChat(name) {
|
||||||
state.selectConversation(conv.key);
|
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) {
|
function plainText(s) {
|
||||||
if (typeof s !== 'string') return '';
|
if (typeof s !== 'string') return '';
|
||||||
// AIM messages often arrive as HTML; render as plain text safely.
|
// AIM messages often arrive as HTML; render as plain text safely.
|
||||||
|
|
@ -460,7 +475,7 @@ async function afterLogin(screenName) {
|
||||||
ui.showChat(screenName);
|
ui.showChat(screenName);
|
||||||
ui.setMessageStyle(ui.getMessageStyle());
|
ui.setMessageStyle(ui.getMessageStyle());
|
||||||
ui.setTocStatus(false);
|
ui.setTocStatus(false);
|
||||||
ui.renderConversations(state);
|
ui.renderConversations(state, closeConversation);
|
||||||
ui.renderMessages(state);
|
ui.renderMessages(state);
|
||||||
stream.connect();
|
stream.connect();
|
||||||
await loadBuddies();
|
await loadBuddies();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Web OSCAR Chat</title>
|
<title>Web OSCAR Chat</title>
|
||||||
<link rel="stylesheet" href="/style.css?v=31">
|
<link rel="stylesheet" href="/style.css?v=32">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
|
|
@ -98,6 +98,6 @@
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/app.js?v=31"></script>
|
<script type="module" src="/app.js?v=32"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -82,15 +82,31 @@ export function showBroadcast(text) {
|
||||||
banner.classList.remove('hidden');
|
banner.classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderConversations(state) {
|
export function renderConversations(state, onClose) {
|
||||||
const list = el('conversations');
|
const list = el('conversations');
|
||||||
clear(list);
|
clear(list);
|
||||||
for (const conv of Object.values(state.conversations)) {
|
for (const conv of Object.values(state.conversations)) {
|
||||||
const li = document.createElement('li');
|
const li = document.createElement('li');
|
||||||
const label = conv.type === 'chat' ? `# ${conv.name}` : conv.name;
|
li.className = 'tab' + (state.active === conv.key ? ' active' : '');
|
||||||
li.appendChild(button(label, () => state.selectConversation(conv.key), {
|
|
||||||
active: state.active === conv.key,
|
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);
|
list.appendChild(li);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,29 +155,49 @@ main { padding: 1rem; max-width: 1600px; margin: 0 auto; }
|
||||||
gap: 0.35rem;
|
gap: 0.35rem;
|
||||||
min-width: max-content;
|
min-width: max-content;
|
||||||
}
|
}
|
||||||
.tabs li { margin: 0; }
|
.tabs li.tab {
|
||||||
.tabs button {
|
margin: 0;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: stretch;
|
||||||
background: #1a1f29;
|
background: #1a1f29;
|
||||||
color: var(--muted);
|
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
border-radius: 8px 8px 0 0;
|
border-radius: 8px 8px 0 0;
|
||||||
padding: 0.5rem 0.75rem;
|
max-width: 260px;
|
||||||
font-weight: 500;
|
|
||||||
max-width: 220px;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
}
|
||||||
.tabs button:hover { color: var(--text); background: #232a36; border-color: #4a5568; }
|
.tabs li.tab:hover { background: #232a36; border-color: #4a5568; }
|
||||||
.tabs button.active {
|
.tabs li.tab.active {
|
||||||
color: var(--text);
|
|
||||||
background: var(--panel);
|
background: var(--panel);
|
||||||
border: 2px solid var(--accent);
|
border: 2px solid var(--accent);
|
||||||
border-bottom: 1px solid var(--panel);
|
border-bottom: 1px solid var(--panel);
|
||||||
margin-bottom: -1px;
|
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 { 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; }
|
.chat-header h2 { margin: 0; font-size: 1rem; }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue