feat: sync ephemeral transient messages
Sync telesrv 570ccf8 (feat(ephemeral): implement Layer 228 transient messages). Skipped telesrv docs changes per public sync rules; normalized the public appearance seed label.
This commit is contained in:
parent
3f78eaa2c6
commit
f49c817def
53 changed files with 5793 additions and 112 deletions
13
deploy/migrations/0120_bot_api_ephemeral_payload.down.sql
Normal file
13
deploy/migrations/0120_bot_api_ephemeral_payload.down.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
DELETE FROM public.bot_api_updates
|
||||
WHERE ephemeral_payload IS NOT NULL;
|
||||
|
||||
DROP INDEX IF EXISTS public.bot_api_updates_ephemeral_version_unique;
|
||||
DROP INDEX IF EXISTS public.bot_api_updates_message_source_unique;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP CONSTRAINT bot_api_updates_ephemeral_shape_check,
|
||||
DROP COLUMN ephemeral_payload;
|
||||
|
||||
CREATE UNIQUE INDEX bot_api_updates_message_source_unique
|
||||
ON public.bot_api_updates (bot_user_id, update_kind, peer_type, peer_id, message_id, source_pts)
|
||||
WHERE update_kind IN ('message', 'edited_message');
|
||||
61
deploy/migrations/0120_bot_api_ephemeral_payload.up.sql
Normal file
61
deploy/migrations/0120_bot_api_ephemeral_payload.up.sql
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
ALTER TABLE public.bot_api_updates
|
||||
ADD COLUMN ephemeral_payload jsonb;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
ADD CONSTRAINT bot_api_updates_ephemeral_shape_check CHECK (
|
||||
ephemeral_payload IS NULL
|
||||
OR (
|
||||
peer_type = 'channel'
|
||||
AND peer_id > 0
|
||||
AND message_id > 0
|
||||
AND source_pts = 0
|
||||
AND jsonb_typeof(ephemeral_payload) = 'object'
|
||||
AND jsonb_typeof(ephemeral_payload -> 'Message') = 'object'
|
||||
AND (ephemeral_payload #>> '{Message,ID}') IS NOT NULL
|
||||
AND (ephemeral_payload #>> '{Message,Peer,Type}') IS NOT NULL
|
||||
AND (ephemeral_payload #>> '{Message,Peer,ID}') IS NOT NULL
|
||||
AND (ephemeral_payload #>> '{Message,SenderUserID}') IS NOT NULL
|
||||
AND (ephemeral_payload #>> '{Message,ReceiverUserID}') IS NOT NULL
|
||||
AND (ephemeral_payload #>> '{Message,Version}') IS NOT NULL
|
||||
AND NOT ((ephemeral_payload -> 'Message') ?| ARRAY[
|
||||
'RandomID', 'OriginDevice', 'PayloadHash', 'CreatedAt', 'Deleted'
|
||||
])
|
||||
AND (
|
||||
NOT (ephemeral_payload ? 'ReplyTo')
|
||||
OR (
|
||||
jsonb_typeof(ephemeral_payload -> 'ReplyTo') = 'object'
|
||||
AND NOT ((ephemeral_payload -> 'ReplyTo') ?| ARRAY[
|
||||
'RandomID', 'OriginDevice', 'PayloadHash', 'CreatedAt', 'Deleted'
|
||||
])
|
||||
)
|
||||
)
|
||||
AND (ephemeral_payload #>> '{Message,ID}')::integer = message_id
|
||||
AND (ephemeral_payload #>> '{Message,Peer,Type}') = peer_type
|
||||
AND (ephemeral_payload #>> '{Message,Peer,ID}')::bigint = peer_id
|
||||
AND (
|
||||
(update_kind = 'callback_query'
|
||||
AND (ephemeral_payload #>> '{Message,SenderUserID}')::bigint = bot_user_id)
|
||||
OR
|
||||
(update_kind IN ('message', 'edited_message')
|
||||
AND (ephemeral_payload #>> '{Message,ReceiverUserID}')::bigint = bot_user_id)
|
||||
)
|
||||
AND (ephemeral_payload #>> '{Message,Version}')::bigint > 0
|
||||
)
|
||||
);
|
||||
|
||||
DROP INDEX public.bot_api_updates_message_source_unique;
|
||||
|
||||
CREATE UNIQUE INDEX bot_api_updates_message_source_unique
|
||||
ON public.bot_api_updates (bot_user_id, update_kind, peer_type, peer_id, message_id, source_pts)
|
||||
WHERE update_kind IN ('message', 'edited_message') AND ephemeral_payload IS NULL;
|
||||
|
||||
CREATE UNIQUE INDEX bot_api_updates_ephemeral_version_unique
|
||||
ON public.bot_api_updates (
|
||||
bot_user_id,
|
||||
update_kind,
|
||||
peer_type,
|
||||
peer_id,
|
||||
message_id,
|
||||
((ephemeral_payload #>> '{Message,Version}')::bigint)
|
||||
)
|
||||
WHERE update_kind IN ('message', 'edited_message') AND ephemeral_payload IS NOT NULL;
|
||||
1
deploy/migrations/0121_ephemeral_abuse_reports.down.sql
Normal file
1
deploy/migrations/0121_ephemeral_abuse_reports.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE IF EXISTS public.ephemeral_abuse_reports;
|
||||
23
deploy/migrations/0121_ephemeral_abuse_reports.up.sql
Normal file
23
deploy/migrations/0121_ephemeral_abuse_reports.up.sql
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
CREATE TABLE public.ephemeral_abuse_reports (
|
||||
id bigserial PRIMARY KEY,
|
||||
reporter_user_id bigint NOT NULL CHECK (reporter_user_id > 0),
|
||||
channel_id bigint NOT NULL CHECK (channel_id > 0),
|
||||
ephemeral_message_id integer NOT NULL CHECK (ephemeral_message_id > 0),
|
||||
sender_user_id bigint NOT NULL CHECK (sender_user_id > 0),
|
||||
receiver_user_id bigint NOT NULL CHECK (receiver_user_id = reporter_user_id),
|
||||
report_option text NOT NULL CHECK (length(report_option) BETWEEN 1 AND 64),
|
||||
report_comment text NOT NULL DEFAULT '' CHECK (length(report_comment) <= 4096),
|
||||
comment_hash bytea NOT NULL CHECK (octet_length(comment_hash) = 32),
|
||||
payload_hash bytea NOT NULL CHECK (octet_length(payload_hash) = 32),
|
||||
evidence jsonb NOT NULL CHECK (jsonb_typeof(evidence) = 'object'),
|
||||
created_at timestamptz NOT NULL,
|
||||
CONSTRAINT ephemeral_abuse_reports_idempotency UNIQUE (
|
||||
reporter_user_id, channel_id, ephemeral_message_id, report_option, comment_hash
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX ephemeral_abuse_reports_created_at_idx
|
||||
ON public.ephemeral_abuse_reports (created_at DESC, id DESC);
|
||||
|
||||
CREATE INDEX ephemeral_abuse_reports_sender_created_idx
|
||||
ON public.ephemeral_abuse_reports (sender_user_id, created_at DESC, id DESC);
|
||||
Loading…
Add table
Add a link
Reference in a new issue