feat: port private messaging (私信) from upstream

- Add conversations/messages tables to schema.sql (upstream missed them)
- API: GET/POST /api/conversations, GET/POST /api/conversations/[id]/messages, PUT /api/messages/[id]/read
- Chat UI: conversation list modal, chat window with 3s polling, unread badge
- Navbar message entry opens DM list; user profile has 发私信 button
- Access control: only conversation participants (403 otherwise)
This commit is contained in:
lezi-fun committed 2026-08-09 21:01:55 +08:00
1 parent 5ef8d4b1ff
commit 300ad5959c
11 files changed
+522 -3

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
// PUT /api/messages/[id]/read — 标记消息已读
import pool from '@/lib/db';
import { getUser } from '@/lib/auth';
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
export async function PUT(req, { params }) {
const user = getUser(req);
if (!user) {
return Response.json({ error: '请先登录' }, { status: 401 });
}
if (!UUID_RE.test(params.id)) {
return Response.json({ error: '服务器错误' }, { status: 500 });
}
try {
await pool.query(`
UPDATE messages SET is_read = true
WHERE id = $1 AND sender_id != $2
`, [params.id, user.id]);
return Response.json({ success: true });
} catch {
return Response.json({ error: '服务器错误' }, { status: 500 });
}
}