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
This commit is contained in:
@@ -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'}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user