merged from gramsrv upstream

This commit is contained in:
onysd 2026-09-01 12:06:31 +03:00
parent 79c64ee916
commit 21a0856587
651 changed files with 54774 additions and 4590 deletions

View file

@ -1014,6 +1014,19 @@ WHERE user_id = $1
ORDER BY date DESC, peer_type ASC, peer_id DESC, top_message_id DESC
LIMIT sqlc.arg(limit_count);
-- name: ListDialogDraftsByPeers :many
SELECT d.draft::text AS draft_json
FROM dialog_drafts d
WHERE d.user_id = sqlc.arg(user_id)
AND d.top_message_id = 0
AND EXISTS (
SELECT 1
FROM unnest(sqlc.arg(peer_types)::text[]) WITH ORDINALITY AS requested_type(peer_type, ord)
JOIN unnest(sqlc.arg(peer_ids)::bigint[]) WITH ORDINALITY AS requested_id(peer_id, ord) USING (ord)
WHERE requested_type.peer_type = d.peer_type
AND requested_id.peer_id = d.peer_id
);
-- name: ClearDialogDrafts :many
WITH doomed AS (
SELECT d.user_id, d.peer_type, d.peer_id, d.top_message_id

View file

@ -562,6 +562,18 @@ base AS NOT MATERIALIZED (
)
)
)
AND (
NOT sqlc.arg(phone_calls_only)::boolean
OR m.media #>> '{service_action,kind}' = 'phone_call'
)
AND (
NOT sqlc.arg(missed_phone_calls_only)::boolean
OR (
NOT m.outgoing
AND m.media #>> '{service_action,kind}' = 'phone_call'
AND m.media #>> '{service_action,call,reason}' = 'missed'
)
)
AND (
sqlc.arg(saved_peer_type)::text = ''
OR (m.saved_peer_type = sqlc.arg(saved_peer_type)::text AND m.saved_peer_id = sqlc.arg(saved_peer_id)::bigint)
@ -840,6 +852,18 @@ WHERE m.owner_user_id = sqlc.arg(owner_user_id)::bigint
)
)
)
AND (
NOT sqlc.arg(phone_calls_only)::boolean
OR m.media #>> '{service_action,kind}' = 'phone_call'
)
AND (
NOT sqlc.arg(missed_phone_calls_only)::boolean
OR (
NOT m.outgoing
AND m.media #>> '{service_action,kind}' = 'phone_call'
AND m.media #>> '{service_action,call,reason}' = 'missed'
)
)
AND (
sqlc.arg(saved_peer_type)::text = ''
OR (m.saved_peer_type = sqlc.arg(saved_peer_type)::text AND m.saved_peer_id = sqlc.arg(saved_peer_id)::bigint)
@ -899,6 +923,18 @@ WHERE m.owner_user_id = sqlc.arg(owner_user_id)::bigint
)
)
)
AND (
NOT sqlc.arg(phone_calls_only)::boolean
OR m.media #>> '{service_action,kind}' = 'phone_call'
)
AND (
NOT sqlc.arg(missed_phone_calls_only)::boolean
OR (
NOT m.outgoing
AND m.media #>> '{service_action,kind}' = 'phone_call'
AND m.media #>> '{service_action,call,reason}' = 'missed'
)
)
AND (
sqlc.arg(saved_peer_type)::text = ''
OR (m.saved_peer_type = sqlc.arg(saved_peer_type)::text AND m.saved_peer_id = sqlc.arg(saved_peer_id)::bigint)

View file

@ -121,6 +121,7 @@ SELECT
COALESCE(m.effect, 0)::bigint AS effect,
COALESCE(m.reply_markup::text, '{}')::text AS reply_markup_json,
COALESCE(m.rich_message::text, '{}')::text AS rich_message_json,
COALESCE(m.deleted, false)::boolean AS message_deleted,
COALESCE(peer_u.id, 0)::bigint AS peer_user_id,
COALESCE(peer_u.access_hash, 0)::bigint AS peer_access_hash,
COALESCE(peer_u.phone, '')::text AS peer_phone,
@ -395,6 +396,7 @@ SELECT
COALESCE(m.effect, 0)::bigint AS effect,
COALESCE(m.reply_markup::text, '{}')::text AS reply_markup_json,
COALESCE(m.rich_message::text, '{}')::text AS rich_message_json,
COALESCE(m.deleted, false)::boolean AS message_deleted,
COALESCE(peer_u.id, 0)::bigint AS peer_user_id,
COALESCE(peer_u.access_hash, 0)::bigint AS peer_access_hash,
COALESCE(peer_u.phone, '')::text AS peer_phone,
@ -495,6 +497,7 @@ WITH doomed AS MATERIALIZED (
FROM dispatch_outbox_user_heads h
WHERE h.status = 'failed'
AND h.updated_at < now() - make_interval(secs => sqlc.arg(older_than_seconds)::int)
AND h.target_user_id = ANY(sqlc.arg(target_user_ids)::bigint[])
ORDER BY h.updated_at ASC, h.target_user_id ASC, h.head_id ASC
LIMIT sqlc.arg(limit_count)
FOR UPDATE OF h SKIP LOCKED