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:
1 parent
5ef8d4b1ff
commit
300ad5959c
11 files changed
+522
-3
No files matched your search
+24
@@ -88,3 +88,27 @@ DROP TRIGGER IF EXISTS update_posts_updated_at ON posts;
|
||||
CREATE TRIGGER update_posts_updated_at
|
||||
BEFORE UPDATE ON posts
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
||||
|
||||
-- ============================================================
|
||||
-- 私信系统(conversations + messages)
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS conversations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user1_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
user2_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
last_message_at TIMESTAMPTZ DEFAULT now(),
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
conversation_id UUID NOT NULL REFERENCES conversations(id) ON DELETE CASCADE,
|
||||
sender_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
content TEXT NOT NULL,
|
||||
is_read BOOLEAN DEFAULT false,
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_conversations_user1 ON conversations(user1_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_conversations_user2 ON conversations(user2_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_conversation ON messages(conversation_id);
|
||||
Reference in new issue
Block a user