merged from gramsrv upstream
This commit is contained in:
parent
79c64ee916
commit
21a0856587
651 changed files with 54774 additions and 4590 deletions
|
|
@ -372,6 +372,46 @@ func (q *Queries) ListDialogDrafts(ctx context.Context, arg ListDialogDraftsPara
|
|||
return items, nil
|
||||
}
|
||||
|
||||
const listDialogDraftsByPeers = `-- name: ListDialogDraftsByPeers :many
|
||||
SELECT d.draft::text AS draft_json
|
||||
FROM dialog_drafts d
|
||||
WHERE d.user_id = $1
|
||||
AND d.top_message_id = 0
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM unnest($2::text[]) WITH ORDINALITY AS requested_type(peer_type, ord)
|
||||
JOIN unnest($3::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
|
||||
)
|
||||
`
|
||||
|
||||
type ListDialogDraftsByPeersParams struct {
|
||||
UserID int64
|
||||
PeerTypes []string
|
||||
PeerIds []int64
|
||||
}
|
||||
|
||||
func (q *Queries) ListDialogDraftsByPeers(ctx context.Context, arg ListDialogDraftsByPeersParams) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, listDialogDraftsByPeers, arg.UserID, arg.PeerTypes, arg.PeerIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var draft_json string
|
||||
if err := rows.Scan(&draft_json); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, draft_json)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDialogFolders = `-- name: ListDialogFolders :many
|
||||
SELECT
|
||||
filter_id,
|
||||
|
|
|
|||
|
|
@ -44,39 +44,53 @@ WHERE m.owner_user_id = $1::bigint
|
|||
)
|
||||
)
|
||||
AND (
|
||||
$14::text = ''
|
||||
OR (m.saved_peer_type = $14::text AND m.saved_peer_id = $15::bigint)
|
||||
NOT $14::boolean
|
||||
OR m.media #>> '{service_action,kind}' = 'phone_call'
|
||||
)
|
||||
AND (
|
||||
cardinality($16::text[]) = 0
|
||||
NOT $15::boolean
|
||||
OR (
|
||||
NOT m.outgoing
|
||||
AND m.media #>> '{service_action,kind}' = 'phone_call'
|
||||
AND m.media #>> '{service_action,call,reason}' = 'missed'
|
||||
)
|
||||
)
|
||||
AND (
|
||||
$16::text = ''
|
||||
OR (m.saved_peer_type = $16::text AND m.saved_peer_id = $17::bigint)
|
||||
)
|
||||
AND (
|
||||
cardinality($18::text[]) = 0
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM saved_message_reaction_tags tag
|
||||
WHERE tag.user_id = m.owner_user_id
|
||||
AND tag.message_box_id = m.box_id
|
||||
AND (tag.reaction_type || ':' || tag.reaction_value)
|
||||
= ANY($16::text[])
|
||||
= ANY($18::text[])
|
||||
)
|
||||
)
|
||||
`
|
||||
|
||||
type CountMessagesByUserParams struct {
|
||||
OwnerUserID int64
|
||||
HasPeer bool
|
||||
PeerType string
|
||||
PeerID int64
|
||||
RestrictPeerIds bool
|
||||
PeerIds []int64
|
||||
Query string
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
MaxID int32
|
||||
MinID int32
|
||||
PinnedOnly bool
|
||||
MusicOnly bool
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
SavedReactionKeys []string
|
||||
OwnerUserID int64
|
||||
HasPeer bool
|
||||
PeerType string
|
||||
PeerID int64
|
||||
RestrictPeerIds bool
|
||||
PeerIds []int64
|
||||
Query string
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
MaxID int32
|
||||
MinID int32
|
||||
PinnedOnly bool
|
||||
MusicOnly bool
|
||||
PhoneCallsOnly bool
|
||||
MissedPhoneCallsOnly bool
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
SavedReactionKeys []string
|
||||
}
|
||||
|
||||
// ListMessagesByUser total CTE 的独立化:相同 base 过滤(不含分页 anchor),
|
||||
|
|
@ -96,6 +110,8 @@ func (q *Queries) CountMessagesByUser(ctx context.Context, arg CountMessagesByUs
|
|||
arg.MinID,
|
||||
arg.PinnedOnly,
|
||||
arg.MusicOnly,
|
||||
arg.PhoneCallsOnly,
|
||||
arg.MissedPhoneCallsOnly,
|
||||
arg.SavedPeerType,
|
||||
arg.SavedPeerID,
|
||||
arg.SavedReactionKeys,
|
||||
|
|
@ -2338,50 +2354,64 @@ WHERE m.owner_user_id = $1::bigint
|
|||
)
|
||||
)
|
||||
AND (
|
||||
$14::text = ''
|
||||
OR (m.saved_peer_type = $14::text AND m.saved_peer_id = $15::bigint)
|
||||
NOT $14::boolean
|
||||
OR m.media #>> '{service_action,kind}' = 'phone_call'
|
||||
)
|
||||
AND (
|
||||
cardinality($16::text[]) = 0
|
||||
NOT $15::boolean
|
||||
OR (
|
||||
NOT m.outgoing
|
||||
AND m.media #>> '{service_action,kind}' = 'phone_call'
|
||||
AND m.media #>> '{service_action,call,reason}' = 'missed'
|
||||
)
|
||||
)
|
||||
AND (
|
||||
$16::text = ''
|
||||
OR (m.saved_peer_type = $16::text AND m.saved_peer_id = $17::bigint)
|
||||
)
|
||||
AND (
|
||||
cardinality($18::text[]) = 0
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM saved_message_reaction_tags tag
|
||||
WHERE tag.user_id = m.owner_user_id
|
||||
AND tag.message_box_id = m.box_id
|
||||
AND (tag.reaction_type || ':' || tag.reaction_value)
|
||||
= ANY($16::text[])
|
||||
= ANY($18::text[])
|
||||
)
|
||||
)
|
||||
AND (
|
||||
($17::int > 0 AND m.message_date < $17::int)
|
||||
OR ($17::int <= 0 AND ($18::int <= 0 OR m.box_id < $18::int))
|
||||
($19::int > 0 AND m.message_date < $19::int)
|
||||
OR ($19::int <= 0 AND ($20::int <= 0 OR m.box_id < $20::int))
|
||||
)
|
||||
ORDER BY m.box_id DESC
|
||||
OFFSET GREATEST($19::int, 0)
|
||||
LIMIT $20::int
|
||||
OFFSET GREATEST($21::int, 0)
|
||||
LIMIT $22::int
|
||||
`
|
||||
|
||||
type ListMessagesBackwardParams struct {
|
||||
OwnerUserID int64
|
||||
HasPeer bool
|
||||
PeerType string
|
||||
PeerID int64
|
||||
RestrictPeerIds bool
|
||||
PeerIds []int64
|
||||
Query string
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
MaxID int32
|
||||
MinID int32
|
||||
PinnedOnly bool
|
||||
MusicOnly bool
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
SavedReactionKeys []string
|
||||
OffsetDate int32
|
||||
OffsetID int32
|
||||
RowOffset int32
|
||||
LimitCount int32
|
||||
OwnerUserID int64
|
||||
HasPeer bool
|
||||
PeerType string
|
||||
PeerID int64
|
||||
RestrictPeerIds bool
|
||||
PeerIds []int64
|
||||
Query string
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
MaxID int32
|
||||
MinID int32
|
||||
PinnedOnly bool
|
||||
MusicOnly bool
|
||||
PhoneCallsOnly bool
|
||||
MissedPhoneCallsOnly bool
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
SavedReactionKeys []string
|
||||
OffsetDate int32
|
||||
OffsetID int32
|
||||
RowOffset int32
|
||||
LimitCount int32
|
||||
}
|
||||
|
||||
type ListMessagesBackwardRow struct {
|
||||
|
|
@ -2480,6 +2510,8 @@ func (q *Queries) ListMessagesBackward(ctx context.Context, arg ListMessagesBack
|
|||
arg.MinID,
|
||||
arg.PinnedOnly,
|
||||
arg.MusicOnly,
|
||||
arg.PhoneCallsOnly,
|
||||
arg.MissedPhoneCallsOnly,
|
||||
arg.SavedPeerType,
|
||||
arg.SavedPeerID,
|
||||
arg.SavedReactionKeys,
|
||||
|
|
@ -2703,25 +2735,37 @@ base AS NOT MATERIALIZED (
|
|||
)
|
||||
)
|
||||
AND (
|
||||
$18::text = ''
|
||||
OR (m.saved_peer_type = $18::text AND m.saved_peer_id = $19::bigint)
|
||||
NOT $18::boolean
|
||||
OR m.media #>> '{service_action,kind}' = 'phone_call'
|
||||
)
|
||||
AND (
|
||||
cardinality($20::text[]) = 0
|
||||
NOT $19::boolean
|
||||
OR (
|
||||
NOT m.outgoing
|
||||
AND m.media #>> '{service_action,kind}' = 'phone_call'
|
||||
AND m.media #>> '{service_action,call,reason}' = 'missed'
|
||||
)
|
||||
)
|
||||
AND (
|
||||
$20::text = ''
|
||||
OR (m.saved_peer_type = $20::text AND m.saved_peer_id = $21::bigint)
|
||||
)
|
||||
AND (
|
||||
cardinality($22::text[]) = 0
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM saved_message_reaction_tags tag
|
||||
WHERE tag.user_id = m.owner_user_id
|
||||
AND tag.message_box_id = m.box_id
|
||||
AND (tag.reaction_type || ':' || tag.reaction_value)
|
||||
= ANY($20::text[])
|
||||
= ANY($22::text[])
|
||||
)
|
||||
)
|
||||
),
|
||||
total AS (
|
||||
SELECT count(*)::int AS total_count
|
||||
FROM base
|
||||
WHERE $21::boolean
|
||||
WHERE $23::boolean
|
||||
),
|
||||
backward AS (
|
||||
SELECT b.box_id, b.private_message_id, b.owner_user_id, b.peer_type, b.peer_id, b.from_user_id, b.message_date, b.ttl_period, b.expires_at, b.edit_date, b.hide_edited, b.outgoing, b.body, b.entities_json, b.silent, b.noforwards, b.reply_to_msg_id, b.reply_to_peer_type, b.reply_to_peer_id, b.reply_to_top_id, b.reply_to_story_id, b.quote_text, b.quote_entities_json, b.quote_offset, b.fwd_from_peer_type, b.fwd_from_peer_id, b.fwd_from_name, b.fwd_date, b.fwd_saved_from_peer_type, b.fwd_saved_from_peer_id, b.fwd_saved_from_msg_id, b.saved_peer_type, b.saved_peer_id, b.pts, b.media_json, b.media_unread, b.reaction_unread, b.pinned, b.via_bot_id, b.grouped_id, b.effect, b.reply_markup_json, b.rich_message_json, b.peer_user_id, b.peer_access_hash, b.peer_phone, b.peer_first_name, b.peer_last_name, b.peer_username, b.peer_country_code, b.peer_verified, b.peer_support, b.peer_is_bot, b.peer_bot_info_version, b.peer_premium_until, b.peer_emoji_status_document_id, b.peer_emoji_status_until, b.peer_last_seen_at, b.from_user_user_id, b.from_user_access_hash, b.from_user_phone, b.from_user_first_name, b.from_user_last_name, b.from_user_username, b.from_user_country_code, b.from_user_verified, b.from_user_support, b.from_user_is_bot, b.from_user_bot_info_version, b.from_user_premium_until, b.from_user_emoji_status_document_id, b.from_user_emoji_status_until, b.from_user_last_seen_at
|
||||
|
|
@ -2868,27 +2912,29 @@ ORDER BY box_id DESC
|
|||
`
|
||||
|
||||
type ListMessagesByUserParams struct {
|
||||
OwnerUserID int64
|
||||
OffsetID int32
|
||||
OffsetDate int32
|
||||
AddOffset int32
|
||||
LimitCount int32
|
||||
HasPeer bool
|
||||
PeerType string
|
||||
PeerID int64
|
||||
RestrictPeerIds bool
|
||||
PeerIds []int64
|
||||
Query string
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
MaxID int32
|
||||
MinID int32
|
||||
PinnedOnly bool
|
||||
MusicOnly bool
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
SavedReactionKeys []string
|
||||
NeedTotalCount bool
|
||||
OwnerUserID int64
|
||||
OffsetID int32
|
||||
OffsetDate int32
|
||||
AddOffset int32
|
||||
LimitCount int32
|
||||
HasPeer bool
|
||||
PeerType string
|
||||
PeerID int64
|
||||
RestrictPeerIds bool
|
||||
PeerIds []int64
|
||||
Query string
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
MaxID int32
|
||||
MinID int32
|
||||
PinnedOnly bool
|
||||
MusicOnly bool
|
||||
PhoneCallsOnly bool
|
||||
MissedPhoneCallsOnly bool
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
SavedReactionKeys []string
|
||||
NeedTotalCount bool
|
||||
}
|
||||
|
||||
type ListMessagesByUserRow struct {
|
||||
|
|
@ -2987,6 +3033,8 @@ func (q *Queries) ListMessagesByUser(ctx context.Context, arg ListMessagesByUser
|
|||
arg.MinID,
|
||||
arg.PinnedOnly,
|
||||
arg.MusicOnly,
|
||||
arg.PhoneCallsOnly,
|
||||
arg.MissedPhoneCallsOnly,
|
||||
arg.SavedPeerType,
|
||||
arg.SavedPeerID,
|
||||
arg.SavedReactionKeys,
|
||||
|
|
|
|||
|
|
@ -192,6 +192,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,
|
||||
|
|
@ -330,6 +331,7 @@ type BatchListDispatchEventsRow struct {
|
|||
Effect int64
|
||||
ReplyMarkupJson string
|
||||
RichMessageJson string
|
||||
MessageDeleted bool
|
||||
PeerUserID int64
|
||||
PeerAccessHash int64
|
||||
PeerPhone string
|
||||
|
|
@ -466,6 +468,7 @@ func (q *Queries) BatchListDispatchEvents(ctx context.Context, arg BatchListDisp
|
|||
&i.Effect,
|
||||
&i.ReplyMarkupJson,
|
||||
&i.RichMessageJson,
|
||||
&i.MessageDeleted,
|
||||
&i.PeerUserID,
|
||||
&i.PeerAccessHash,
|
||||
&i.PeerPhone,
|
||||
|
|
@ -703,8 +706,9 @@ WITH doomed AS MATERIALIZED (
|
|||
FROM dispatch_outbox_user_heads h
|
||||
WHERE h.status = 'failed'
|
||||
AND h.updated_at < now() - make_interval(secs => $1::int)
|
||||
AND h.target_user_id = ANY($2::bigint[])
|
||||
ORDER BY h.updated_at ASC, h.target_user_id ASC, h.head_id ASC
|
||||
LIMIT $2
|
||||
LIMIT $3
|
||||
FOR UPDATE OF h SKIP LOCKED
|
||||
),
|
||||
deleted AS (
|
||||
|
|
@ -720,6 +724,7 @@ FROM deleted
|
|||
|
||||
type DeleteFailedDispatchOutboxParams struct {
|
||||
OlderThanSeconds int32
|
||||
TargetUserIds []int64
|
||||
LimitCount int32
|
||||
}
|
||||
|
||||
|
|
@ -727,7 +732,7 @@ type DeleteFailedDispatchOutboxParams struct {
|
|||
// claim/completion 保持同一 user_heads→outbox 锁序。删除的只是在线任务,durable
|
||||
// user_update_events 不动,故客户端仍可经 difference 恢复。
|
||||
func (q *Queries) DeleteFailedDispatchOutbox(ctx context.Context, arg DeleteFailedDispatchOutboxParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, deleteFailedDispatchOutbox, arg.OlderThanSeconds, arg.LimitCount)
|
||||
row := q.db.QueryRow(ctx, deleteFailedDispatchOutbox, arg.OlderThanSeconds, arg.TargetUserIds, arg.LimitCount)
|
||||
var deleted_count int32
|
||||
err := row.Scan(&deleted_count)
|
||||
return deleted_count, err
|
||||
|
|
@ -846,6 +851,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,
|
||||
|
|
@ -987,6 +993,7 @@ type ListUserUpdateEventsAfterRow struct {
|
|||
Effect int64
|
||||
ReplyMarkupJson string
|
||||
RichMessageJson string
|
||||
MessageDeleted bool
|
||||
PeerUserID int64
|
||||
PeerAccessHash int64
|
||||
PeerPhone string
|
||||
|
|
@ -1121,6 +1128,7 @@ func (q *Queries) ListUserUpdateEventsAfter(ctx context.Context, arg ListUserUpd
|
|||
&i.Effect,
|
||||
&i.ReplyMarkupJson,
|
||||
&i.RichMessageJson,
|
||||
&i.MessageDeleted,
|
||||
&i.PeerUserID,
|
||||
&i.PeerAccessHash,
|
||||
&i.PeerPhone,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue