From af3a26fcdfb0e9af9c528189eaaccd0041bbbac7 Mon Sep 17 00:00:00 2001 From: clawbot Date: Tue, 10 Feb 2026 17:53:17 -0800 Subject: [PATCH] feat(web): update SPA to use unified command endpoint - Session creation uses /session instead of /register - JOIN/PART via POST /messages with command field - NICK changes via POST /messages with NICK command - Messages sent as PRIVMSG commands with body array - DMs use PRIVMSG command format --- web/src/app.jsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/web/src/app.jsx b/web/src/app.jsx index 2206972..846dd51 100644 --- a/web/src/app.jsx +++ b/web/src/app.jsx @@ -51,7 +51,7 @@ function LoginScreen({ onLogin }) { e.preventDefault(); setError(''); try { - const res = await api('/register', { + const res = await api('/session', { method: 'POST', body: JSON.stringify({ nick: nick.trim() }) }); @@ -201,7 +201,7 @@ function App() { name = name.trim(); if (!name.startsWith('#')) name = '#' + name; try { - await api('/channels/join', { method: 'POST', body: JSON.stringify({ channel: name }) }); + await api('/messages', { method: 'POST', body: JSON.stringify({ command: 'JOIN', to: name }) }); setTabs(prev => { if (prev.find(t => t.type === 'channel' && t.name === name)) return prev; return [...prev, { type: 'channel', name }]; @@ -215,9 +215,8 @@ function App() { }; const partChannel = async (name) => { - const chName = name.replace('#', ''); try { - await api(`/channels/${chName}`, { method: 'DELETE' }); + await api('/messages', { method: 'POST', body: JSON.stringify({ command: 'PART', to: name }) }); } catch (err) { /* ignore */ } setTabs(prev => { const next = prev.filter(t => !(t.type === 'channel' && t.name === name)); @@ -267,15 +266,21 @@ function App() { const target = parts[1]; const msg = parts.slice(2).join(' '); try { - await api('/messages', { method: 'POST', body: JSON.stringify({ to: target, content: msg }) }); + await api('/messages', { method: 'POST', body: JSON.stringify({ command: 'PRIVMSG', to: target, body: [msg] }) }); openDM(target); } catch (err) { addSystemMessage('server', `Failed to send DM: ${err.data?.error || 'error'}`); } return; } - if (cmd === '/nick') { - addSystemMessage('server', 'Nick changes not yet supported'); + if (cmd === '/nick' && parts[1]) { + try { + await api('/messages', { method: 'POST', body: JSON.stringify({ command: 'NICK', body: [parts[1]] }) }); + setNick(parts[1]); + addSystemMessage('server', `Nick changed to ${parts[1]}`); + } catch (err) { + addSystemMessage('server', `Nick change failed: ${err.data?.error || 'error'}`); + } return; } addSystemMessage('server', `Unknown command: ${cmd}`); @@ -284,7 +289,7 @@ function App() { const to = tab.type === 'channel' ? tab.name : tab.name; try { - await api('/messages', { method: 'POST', body: JSON.stringify({ to, content: text }) }); + await api('/messages', { method: 'POST', body: JSON.stringify({ command: 'PRIVMSG', to, body: [text] }) }); } catch (err) { addSystemMessage(tab.name, `Send failed: ${err.data?.error || 'error'}`); }