mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
chat, little buggy
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
-- Chat messages, owned by the `chat` worker. One row per message posted to a thread;
|
||||
-- columns rather than a JSON blob (mirroring the reference model), since every field is a
|
||||
-- scalar the server reads: threads are listed newest-first by (chat_thread_id,
|
||||
-- chat_message_id), and `time_sent` is carried for display only.
|
||||
--
|
||||
-- `chat_message_id` is server-assigned (AUTOINCREMENT) so ids are unique across every
|
||||
-- thread, matching the client's expectation of a global message id. `contents` is the
|
||||
-- client's envelope — `{"Type":0,"Version":1,"Data":"..."}` — stored verbatim as an
|
||||
-- opaque string and served back untouched, so new message types need no schema change.
|
||||
-- `moderation_state` is the ChatModerationState enum (0 = none). Kept in sync with
|
||||
-- SCHEMA_DDL in src/message-db.ts.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message (
|
||||
chat_message_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
chat_thread_id INTEGER NOT NULL,
|
||||
sender_player_id INTEGER NOT NULL,
|
||||
time_sent TEXT NOT NULL,
|
||||
contents TEXT NOT NULL,
|
||||
moderation_state INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_thread ON message (chat_thread_id, chat_message_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_sender ON message (sender_player_id);
|
||||
@@ -0,0 +1,37 @@
|
||||
-- Chat threads and their membership, owned by the `chat` worker.
|
||||
--
|
||||
-- A thread is a conversation — a DM pair, a group chat, or a system thread. Membership
|
||||
-- in `thread_member` is the authorization gate: a player may read or post to a thread
|
||||
-- only if they hold a row here, and the same rows render the `playerIds` array the
|
||||
-- client shows. There is deliberately no FK to accounts, here or on
|
||||
-- `message.sender_player_id`: that table belongs to the `auth` worker, and a thread
|
||||
-- outlives the accounts in it.
|
||||
--
|
||||
-- `latest_message_id` is denormalized onto the thread so the thread list renders from
|
||||
-- one indexed row per thread instead of a per-thread MAX() over `message`; it also
|
||||
-- orders that list (message ids being monotonic, newest thread = highest id). Kept in
|
||||
-- sync on every insert — see touchThread in src/thread-db.ts.
|
||||
--
|
||||
-- The per-viewer fields live on the membership row, not the thread: two players in one
|
||||
-- DM have independent read positions, snoozes, and favorites. Kept in sync with
|
||||
-- THREAD_SCHEMA_DDL in src/thread-db.ts.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_thread (
|
||||
chat_thread_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
-- Null for DMs and unnamed groups; the client falls back to rendering the members.
|
||||
chat_thread_name TEXT,
|
||||
latest_message_id INTEGER,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_thread_latest ON message_thread (latest_message_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS thread_member (
|
||||
chat_thread_id INTEGER NOT NULL,
|
||||
player_id INTEGER NOT NULL,
|
||||
last_read_message_id INTEGER,
|
||||
snoozed_until TEXT,
|
||||
is_favorited INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (chat_thread_id, player_id)
|
||||
);
|
||||
-- The thread-list query is "every thread this player is in", so player_id leads.
|
||||
CREATE INDEX IF NOT EXISTS idx_thread_member_player ON thread_member (player_id);
|
||||
Reference in New Issue
Block a user