Forum: reports for moderators and private messages by request
Any logged-in user can report a post, or a private message received; a possible crisis shows the helplines at once. Moderators get the open reports (crisis first) with what was reported, remove or close them, and every step goes to the log; the operator gets a Telegram notice of each new report (kind and link only). Private conversations start with a request and a short introduction (from the Kereső rank, a few a day); the recipient accepts, declines silently or blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
-- The forum, second round (docs/kozosseg.md): private messages that start
|
||||
-- with a request, and reports of posts and messages (the DSA's notice and
|
||||
-- action), handled by moderators.
|
||||
|
||||
-- One conversation per pair of members (user_a < user_b). It starts as a
|
||||
-- request with a short introduction; the recipient accepts, declines
|
||||
-- (silently: the sender is not told) or blocks.
|
||||
CREATE TABLE forum.conversations (
|
||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
user_a uuid NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
user_b uuid NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
requested_by uuid NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
intro text NOT NULL,
|
||||
status text NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'declined', 'blocked')),
|
||||
-- Who blocked (the other may not send a new request).
|
||||
blocked_by uuid REFERENCES users ON DELETE CASCADE,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
responded_at timestamptz,
|
||||
last_message_at timestamptz,
|
||||
UNIQUE (user_a, user_b),
|
||||
CONSTRAINT conversations_ordered CHECK (user_a < user_b),
|
||||
CONSTRAINT conversations_requester CHECK (requested_by IN (user_a, user_b))
|
||||
);
|
||||
CREATE INDEX conversations_b_idx ON forum.conversations (user_b);
|
||||
|
||||
CREATE TABLE forum.messages (
|
||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
conversation_id bigint NOT NULL REFERENCES forum.conversations ON DELETE CASCADE,
|
||||
sender_id uuid REFERENCES users ON DELETE SET NULL,
|
||||
body text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX messages_conversation_idx ON forum.messages (conversation_id, id);
|
||||
|
||||
-- How far each member has read a conversation.
|
||||
CREATE TABLE forum.conversation_reads (
|
||||
conversation_id bigint NOT NULL REFERENCES forum.conversations ON DELETE CASCADE,
|
||||
user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
last_message_id bigint NOT NULL,
|
||||
PRIMARY KEY (conversation_id, user_id)
|
||||
);
|
||||
|
||||
-- A report of a post or a private message. Moderators see a reported
|
||||
-- message (and the conversation around it) only through its report.
|
||||
CREATE TABLE forum.reports (
|
||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
post_id bigint REFERENCES forum.posts ON DELETE CASCADE,
|
||||
message_id bigint REFERENCES forum.messages ON DELETE CASCADE,
|
||||
reporter_id uuid REFERENCES users ON DELETE SET NULL,
|
||||
kind text NOT NULL CHECK (kind IN ('spam', 'ad', 'rude', 'crisis', 'illegal', 'other')),
|
||||
note text NOT NULL DEFAULT '',
|
||||
status text NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'resolved', 'dismissed')),
|
||||
handled_by uuid REFERENCES users ON DELETE SET NULL,
|
||||
handled_at timestamptz,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
-- The operator's Telegram notice went out (worker notify task).
|
||||
notified_at timestamptz,
|
||||
CONSTRAINT reports_one_target CHECK ((post_id IS NULL) <> (message_id IS NULL))
|
||||
);
|
||||
CREATE UNIQUE INDEX reports_post_once ON forum.reports (post_id, reporter_id) WHERE status = 'open' AND post_id IS NOT NULL;
|
||||
CREATE UNIQUE INDEX reports_message_once ON forum.reports (message_id, reporter_id) WHERE status = 'open' AND message_id IS NOT NULL;
|
||||
CREATE INDEX reports_open_idx ON forum.reports (created_at) WHERE status = 'open';
|
||||
CREATE INDEX reports_unnotified_idx ON forum.reports (created_at) WHERE notified_at IS NULL;
|
||||
|
||||
ALTER TABLE forum.mod_log DROP CONSTRAINT mod_log_action_check;
|
||||
ALTER TABLE forum.mod_log ADD CONSTRAINT mod_log_action_check
|
||||
CHECK (action IN ('delete_post', 'restore_post', 'delete_thread', 'restore_thread', 'ban', 'unban',
|
||||
'lock', 'unlock', 'pin', 'unpin', 'resolve_report', 'dismiss_report'));
|
||||
ALTER TABLE forum.mod_log ADD COLUMN report_id bigint;
|
||||
Reference in New Issue
Block a user