Adds a narrower spam sanction alongside the existing account freeze: a restricted account keeps every existing membership and conversation, but cannot join new channels/groups (public join or invite link) and cannot start a new conversation with a non-contact. Reachable both as a standalone admin action and as a decision on a reported user's moderation case, with the same idempotent-supersession and appeal wiring freeze already has.
23 lines
983 B
SQL
23 lines
983 B
SQL
CREATE TABLE IF NOT EXISTS account_message_restrictions (
|
|
user_id bigint PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
|
restricted boolean NOT NULL DEFAULT false,
|
|
version bigint NOT NULL DEFAULT 0,
|
|
restricted_since timestamptz,
|
|
restricted_until timestamptz,
|
|
reason text NOT NULL DEFAULT '',
|
|
actor text NOT NULL DEFAULT '',
|
|
command_id text NOT NULL DEFAULT '',
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
CONSTRAINT account_message_restrictions_user_id_check CHECK (user_id > 0),
|
|
CONSTRAINT account_message_restrictions_shape_check CHECK (
|
|
(restricted AND restricted_since IS NOT NULL
|
|
AND (restricted_until IS NULL OR restricted_until > restricted_since)
|
|
AND (restricted_until IS NULL OR restricted_until <= to_timestamp(2147483647)))
|
|
OR
|
|
(NOT restricted AND restricted_since IS NULL AND restricted_until IS NULL)
|
|
)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS account_message_restrictions_restricted_idx
|
|
ON account_message_restrictions (user_id)
|
|
WHERE restricted;
|