feat: update web client for unified API endpoints
- Use /state instead of /me for auth check
- Use /messages instead of /poll for message stream
- Use unified POST /messages with 'to' field for all sends
- Update part channel URL to DELETE /channels/{name}
This commit is contained in:
@@ -42,7 +42,7 @@ function LoginScreen({ onLogin }) {
|
||||
// Check for saved token
|
||||
const saved = localStorage.getItem('chat_token');
|
||||
if (saved) {
|
||||
api('/me').then(u => onLogin(u.nick, saved)).catch(() => localStorage.removeItem('chat_token'));
|
||||
api('/state').then(u => onLogin(u.nick, saved)).catch(() => localStorage.removeItem('chat_token'));
|
||||
}
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
@@ -140,7 +140,7 @@ function App() {
|
||||
let alive = true;
|
||||
const poll = async () => {
|
||||
try {
|
||||
const msgs = await api(`/poll?after=${lastMsgId}`);
|
||||
const msgs = await api(`/messages?after=${lastMsgId}`);
|
||||
if (!alive) return;
|
||||
let maxId = lastMsgId;
|
||||
for (const msg of msgs) {
|
||||
@@ -217,7 +217,7 @@ function App() {
|
||||
const partChannel = async (name) => {
|
||||
const chName = name.replace('#', '');
|
||||
try {
|
||||
await api(`/channels/${chName}/part`, { method: 'DELETE' });
|
||||
await api(`/channels/${chName}`, { method: 'DELETE' });
|
||||
} catch (err) { /* ignore */ }
|
||||
setTabs(prev => {
|
||||
const next = prev.filter(t => !(t.type === 'channel' && t.name === name));
|
||||
@@ -267,7 +267,7 @@ function App() {
|
||||
const target = parts[1];
|
||||
const msg = parts.slice(2).join(' ');
|
||||
try {
|
||||
await api(`/dm/${target}/messages`, { method: 'POST', body: JSON.stringify({ content: msg }) });
|
||||
await api('/messages', { method: 'POST', body: JSON.stringify({ to: target, content: msg }) });
|
||||
openDM(target);
|
||||
} catch (err) {
|
||||
addSystemMessage('server', `Failed to send DM: ${err.data?.error || 'error'}`);
|
||||
@@ -282,19 +282,11 @@ function App() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tab.type === 'channel') {
|
||||
const chName = tab.name.replace('#', '');
|
||||
try {
|
||||
await api(`/channels/${chName}/messages`, { method: 'POST', body: JSON.stringify({ content: text }) });
|
||||
} catch (err) {
|
||||
addSystemMessage(tab.name, `Send failed: ${err.data?.error || 'error'}`);
|
||||
}
|
||||
} else if (tab.type === 'dm') {
|
||||
try {
|
||||
await api(`/dm/${tab.name}/messages`, { method: 'POST', body: JSON.stringify({ content: text }) });
|
||||
} catch (err) {
|
||||
addSystemMessage(tab.name, `Send failed: ${err.data?.error || 'error'}`);
|
||||
}
|
||||
const to = tab.type === 'channel' ? tab.name : tab.name;
|
||||
try {
|
||||
await api('/messages', { method: 'POST', body: JSON.stringify({ to, content: text }) });
|
||||
} catch (err) {
|
||||
addSystemMessage(tab.name, `Send failed: ${err.data?.error || 'error'}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user