Bind history to the recipient session and channel, not the name (closes #148)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
History was selected by msg_to, so whoever next held a released nick, or created a deleted channel again under its old name, could read the earlier holder's messages. Each message row now records the session a DM or INVITE was sent to (to_session_id) and the channel a channel message was sent to (to_channel_id), and GET /api/v1/history selects by those ids. A session's DM history now also follows it across nick changes. Model: opus-5-5
This commit is contained in:
@@ -85,19 +85,25 @@ CREATE TABLE IF NOT EXISTS channel_members (
|
||||
UNIQUE(channel_id, session_id)
|
||||
);
|
||||
|
||||
-- Messages: IRC envelope format
|
||||
-- Messages: IRC envelope format. to_session_id is the session a DM
|
||||
-- or INVITE was sent to, to_channel_id the channel a channel message
|
||||
-- was sent to. History is selected by these ids because nicks and
|
||||
-- channel names are reused once released, and ids are not.
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
uuid TEXT NOT NULL UNIQUE,
|
||||
command TEXT NOT NULL DEFAULT 'PRIVMSG',
|
||||
msg_from TEXT NOT NULL DEFAULT '',
|
||||
msg_to TEXT NOT NULL DEFAULT '',
|
||||
to_session_id INTEGER REFERENCES sessions(id) ON DELETE SET NULL,
|
||||
to_channel_id INTEGER REFERENCES channels(id) ON DELETE SET NULL,
|
||||
params TEXT NOT NULL DEFAULT '[]',
|
||||
body TEXT NOT NULL DEFAULT '[]',
|
||||
meta TEXT NOT NULL DEFAULT '{}',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_to_id ON messages(msg_to, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_to_session ON messages(to_session_id, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_to_channel ON messages(to_channel_id, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_created ON messages(created_at);
|
||||
|
||||
-- Spent hashcash tokens for replay prevention (1-year TTL)
|
||||
|
||||
Reference in New Issue
Block a user