chore: refresh gramsrv public release
This commit is contained in:
parent
75cebe8dbf
commit
70b6820474
1274 changed files with 378751 additions and 59919 deletions
865
internal/store/postgres/sqlcgen/saved_dialog.sql.go
Normal file
865
internal/store/postgres/sqlcgen/saved_dialog.sql.go
Normal file
|
|
@ -0,0 +1,865 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: saved_dialog.sql
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const clearSavedDialogPinsNotInOrder = `-- name: ClearSavedDialogPinsNotInOrder :exec
|
||||
DELETE FROM saved_dialog_pins p
|
||||
WHERE p.user_id = $1::bigint
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM generate_subscripts($2::bigint[], 1) AS g(i)
|
||||
WHERE i <= cardinality($3::text[])
|
||||
AND ($3::text[])[i] = p.peer_type
|
||||
AND ($2::bigint[])[i] = p.peer_id
|
||||
)
|
||||
`
|
||||
|
||||
type ClearSavedDialogPinsNotInOrderParams struct {
|
||||
UserID int64
|
||||
PeerIds []int64
|
||||
PeerTypes []string
|
||||
}
|
||||
|
||||
func (q *Queries) ClearSavedDialogPinsNotInOrder(ctx context.Context, arg ClearSavedDialogPinsNotInOrderParams) error {
|
||||
_, err := q.db.Exec(ctx, clearSavedDialogPinsNotInOrder, arg.UserID, arg.PeerIds, arg.PeerTypes)
|
||||
return err
|
||||
}
|
||||
|
||||
const countSavedDialogPins = `-- name: CountSavedDialogPins :one
|
||||
SELECT count(*)::int AS pin_count
|
||||
FROM saved_dialog_pins
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountSavedDialogPins(ctx context.Context, userID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countSavedDialogPins, userID)
|
||||
var pin_count int32
|
||||
err := row.Scan(&pin_count)
|
||||
return pin_count, err
|
||||
}
|
||||
|
||||
const countSavedDialogs = `-- name: CountSavedDialogs :one
|
||||
SELECT count(*)::int AS dialog_count
|
||||
FROM (
|
||||
SELECT m.saved_peer_type, m.saved_peer_id
|
||||
FROM message_boxes m
|
||||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = 'user'
|
||||
AND m.peer_id = $1::bigint
|
||||
AND NOT m.deleted
|
||||
AND m.saved_peer_type <> ''
|
||||
GROUP BY m.saved_peer_type, m.saved_peer_id
|
||||
) d
|
||||
LEFT JOIN saved_dialog_pins p
|
||||
ON p.user_id = $1::bigint
|
||||
AND p.peer_type = d.saved_peer_type
|
||||
AND p.peer_id = d.saved_peer_id
|
||||
WHERE NOT $2::boolean OR p.user_id IS NULL
|
||||
`
|
||||
|
||||
type CountSavedDialogsParams struct {
|
||||
OwnerUserID int64
|
||||
ExcludePinned bool
|
||||
}
|
||||
|
||||
func (q *Queries) CountSavedDialogs(ctx context.Context, arg CountSavedDialogsParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countSavedDialogs, arg.OwnerUserID, arg.ExcludePinned)
|
||||
var dialog_count int32
|
||||
err := row.Scan(&dialog_count)
|
||||
return dialog_count, err
|
||||
}
|
||||
|
||||
const deleteMessageBoxesBySavedPeerBatch = `-- name: DeleteMessageBoxesBySavedPeerBatch :many
|
||||
WITH target AS (
|
||||
SELECT
|
||||
m.owner_user_id,
|
||||
m.box_id
|
||||
FROM message_boxes m
|
||||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = 'user'
|
||||
AND m.peer_id = $1::bigint
|
||||
AND m.saved_peer_type = $2::text
|
||||
AND m.saved_peer_id = $3::bigint
|
||||
AND ($4::int <= 0 OR m.box_id <= $4::int)
|
||||
AND ($5::int <= 0 OR m.message_date >= $5::int)
|
||||
AND ($6::int <= 0 OR m.message_date <= $6::int)
|
||||
AND NOT m.deleted
|
||||
ORDER BY m.box_id DESC
|
||||
LIMIT $7::int
|
||||
FOR UPDATE SKIP LOCKED
|
||||
),
|
||||
updated AS (
|
||||
UPDATE message_boxes m
|
||||
SET deleted = true
|
||||
FROM target t
|
||||
WHERE m.owner_user_id = t.owner_user_id
|
||||
AND m.box_id = t.box_id
|
||||
RETURNING
|
||||
m.owner_user_id,
|
||||
m.box_id,
|
||||
m.private_message_id,
|
||||
m.message_sender_id,
|
||||
m.peer_type,
|
||||
m.peer_id
|
||||
)
|
||||
SELECT
|
||||
owner_user_id,
|
||||
box_id,
|
||||
private_message_id,
|
||||
message_sender_id,
|
||||
peer_type,
|
||||
peer_id
|
||||
FROM updated
|
||||
ORDER BY box_id ASC
|
||||
`
|
||||
|
||||
type DeleteMessageBoxesBySavedPeerBatchParams struct {
|
||||
OwnerUserID int64
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
MaxID int32
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
LimitCount int32
|
||||
}
|
||||
|
||||
type DeleteMessageBoxesBySavedPeerBatchRow struct {
|
||||
OwnerUserID int64
|
||||
BoxID int32
|
||||
PrivateMessageID int64
|
||||
MessageSenderID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteMessageBoxesBySavedPeerBatch(ctx context.Context, arg DeleteMessageBoxesBySavedPeerBatchParams) ([]DeleteMessageBoxesBySavedPeerBatchRow, error) {
|
||||
rows, err := q.db.Query(ctx, deleteMessageBoxesBySavedPeerBatch,
|
||||
arg.OwnerUserID,
|
||||
arg.SavedPeerType,
|
||||
arg.SavedPeerID,
|
||||
arg.MaxID,
|
||||
arg.MinDate,
|
||||
arg.MaxDate,
|
||||
arg.LimitCount,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []DeleteMessageBoxesBySavedPeerBatchRow
|
||||
for rows.Next() {
|
||||
var i DeleteMessageBoxesBySavedPeerBatchRow
|
||||
if err := rows.Scan(
|
||||
&i.OwnerUserID,
|
||||
&i.BoxID,
|
||||
&i.PrivateMessageID,
|
||||
&i.MessageSenderID,
|
||||
&i.PeerType,
|
||||
&i.PeerID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const deleteSavedDialogPin = `-- name: DeleteSavedDialogPin :execrows
|
||||
DELETE FROM saved_dialog_pins
|
||||
WHERE user_id = $1
|
||||
AND peer_type = $2
|
||||
AND peer_id = $3
|
||||
`
|
||||
|
||||
type DeleteSavedDialogPinParams struct {
|
||||
UserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteSavedDialogPin(ctx context.Context, arg DeleteSavedDialogPinParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteSavedDialogPin, arg.UserID, arg.PeerType, arg.PeerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const hasDeletableMessageBoxBySavedPeer = `-- name: HasDeletableMessageBoxBySavedPeer :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM message_boxes m
|
||||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = 'user'
|
||||
AND m.peer_id = $1::bigint
|
||||
AND m.saved_peer_type = $2::text
|
||||
AND m.saved_peer_id = $3::bigint
|
||||
AND ($4::int <= 0 OR m.box_id <= $4::int)
|
||||
AND ($5::int <= 0 OR m.message_date >= $5::int)
|
||||
AND ($6::int <= 0 OR m.message_date <= $6::int)
|
||||
AND NOT m.deleted
|
||||
LIMIT 1
|
||||
)::boolean AS more
|
||||
`
|
||||
|
||||
type HasDeletableMessageBoxBySavedPeerParams struct {
|
||||
OwnerUserID int64
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
MaxID int32
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
}
|
||||
|
||||
func (q *Queries) HasDeletableMessageBoxBySavedPeer(ctx context.Context, arg HasDeletableMessageBoxBySavedPeerParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, hasDeletableMessageBoxBySavedPeer,
|
||||
arg.OwnerUserID,
|
||||
arg.SavedPeerType,
|
||||
arg.SavedPeerID,
|
||||
arg.MaxID,
|
||||
arg.MinDate,
|
||||
arg.MaxDate,
|
||||
)
|
||||
var more bool
|
||||
err := row.Scan(&more)
|
||||
return more, err
|
||||
}
|
||||
|
||||
const listPinnedSavedDialogTops = `-- name: ListPinnedSavedDialogTops :many
|
||||
WITH tops AS (
|
||||
SELECT m.saved_peer_type, m.saved_peer_id, MAX(m.box_id) AS top_box_id
|
||||
FROM message_boxes m
|
||||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = 'user'
|
||||
AND m.peer_id = $1::bigint
|
||||
AND NOT m.deleted
|
||||
AND m.saved_peer_type <> ''
|
||||
GROUP BY m.saved_peer_type, m.saved_peer_id
|
||||
)
|
||||
SELECT
|
||||
t.saved_peer_type AS dialog_peer_type,
|
||||
t.saved_peer_id AS dialog_peer_id,
|
||||
true::boolean AS dialog_pinned,
|
||||
m.box_id,
|
||||
m.private_message_id,
|
||||
m.owner_user_id,
|
||||
m.peer_type,
|
||||
m.peer_id,
|
||||
m.from_user_id,
|
||||
m.message_date,
|
||||
m.ttl_period,
|
||||
m.expires_at,
|
||||
m.edit_date,
|
||||
m.outgoing,
|
||||
m.body,
|
||||
m.entities::text AS entities_json,
|
||||
m.silent,
|
||||
m.noforwards,
|
||||
m.reply_to_msg_id,
|
||||
m.reply_to_peer_type,
|
||||
m.reply_to_peer_id,
|
||||
m.reply_to_top_id,
|
||||
m.reply_to_story_id,
|
||||
m.quote_text,
|
||||
m.quote_entities::text AS quote_entities_json,
|
||||
m.quote_offset,
|
||||
m.fwd_from_peer_type,
|
||||
m.fwd_from_peer_id,
|
||||
m.fwd_from_name,
|
||||
m.fwd_date,
|
||||
m.fwd_saved_from_peer_type,
|
||||
m.fwd_saved_from_peer_id,
|
||||
m.fwd_saved_from_msg_id,
|
||||
m.saved_peer_type,
|
||||
m.saved_peer_id,
|
||||
m.pts,
|
||||
m.media::text AS media_json,
|
||||
m.media_unread,
|
||||
m.reaction_unread,
|
||||
m.via_bot_id,
|
||||
m.grouped_id,
|
||||
m.effect,
|
||||
m.reply_markup::text AS reply_markup_json,
|
||||
m.rich_message::text AS rich_message_json,
|
||||
m.pinned
|
||||
FROM saved_dialog_pins p
|
||||
JOIN tops t
|
||||
ON t.saved_peer_type = p.peer_type
|
||||
AND t.saved_peer_id = p.peer_id
|
||||
JOIN message_boxes m
|
||||
ON m.owner_user_id = $1::bigint
|
||||
AND m.box_id = t.top_box_id
|
||||
WHERE p.user_id = $1::bigint
|
||||
ORDER BY p.pinned_order ASC, p.peer_id ASC
|
||||
`
|
||||
|
||||
type ListPinnedSavedDialogTopsRow struct {
|
||||
DialogPeerType string
|
||||
DialogPeerID int64
|
||||
DialogPinned bool
|
||||
BoxID int32
|
||||
PrivateMessageID int64
|
||||
OwnerUserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
FromUserID int64
|
||||
MessageDate int32
|
||||
TtlPeriod int32
|
||||
ExpiresAt int32
|
||||
EditDate int32
|
||||
Outgoing bool
|
||||
Body string
|
||||
EntitiesJson string
|
||||
Silent bool
|
||||
Noforwards bool
|
||||
ReplyToMsgID int32
|
||||
ReplyToPeerType string
|
||||
ReplyToPeerID int64
|
||||
ReplyToTopID int32
|
||||
ReplyToStoryID int32
|
||||
QuoteText string
|
||||
QuoteEntitiesJson string
|
||||
QuoteOffset int32
|
||||
FwdFromPeerType string
|
||||
FwdFromPeerID int64
|
||||
FwdFromName string
|
||||
FwdDate int32
|
||||
FwdSavedFromPeerType string
|
||||
FwdSavedFromPeerID int64
|
||||
FwdSavedFromMsgID int32
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
Pts int32
|
||||
MediaJson string
|
||||
MediaUnread bool
|
||||
ReactionUnread bool
|
||||
ViaBotID int64
|
||||
GroupedID int64
|
||||
Effect int64
|
||||
ReplyMarkupJson string
|
||||
RichMessageJson string
|
||||
Pinned bool
|
||||
}
|
||||
|
||||
func (q *Queries) ListPinnedSavedDialogTops(ctx context.Context, ownerUserID int64) ([]ListPinnedSavedDialogTopsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listPinnedSavedDialogTops, ownerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListPinnedSavedDialogTopsRow
|
||||
for rows.Next() {
|
||||
var i ListPinnedSavedDialogTopsRow
|
||||
if err := rows.Scan(
|
||||
&i.DialogPeerType,
|
||||
&i.DialogPeerID,
|
||||
&i.DialogPinned,
|
||||
&i.BoxID,
|
||||
&i.PrivateMessageID,
|
||||
&i.OwnerUserID,
|
||||
&i.PeerType,
|
||||
&i.PeerID,
|
||||
&i.FromUserID,
|
||||
&i.MessageDate,
|
||||
&i.TtlPeriod,
|
||||
&i.ExpiresAt,
|
||||
&i.EditDate,
|
||||
&i.Outgoing,
|
||||
&i.Body,
|
||||
&i.EntitiesJson,
|
||||
&i.Silent,
|
||||
&i.Noforwards,
|
||||
&i.ReplyToMsgID,
|
||||
&i.ReplyToPeerType,
|
||||
&i.ReplyToPeerID,
|
||||
&i.ReplyToTopID,
|
||||
&i.ReplyToStoryID,
|
||||
&i.QuoteText,
|
||||
&i.QuoteEntitiesJson,
|
||||
&i.QuoteOffset,
|
||||
&i.FwdFromPeerType,
|
||||
&i.FwdFromPeerID,
|
||||
&i.FwdFromName,
|
||||
&i.FwdDate,
|
||||
&i.FwdSavedFromPeerType,
|
||||
&i.FwdSavedFromPeerID,
|
||||
&i.FwdSavedFromMsgID,
|
||||
&i.SavedPeerType,
|
||||
&i.SavedPeerID,
|
||||
&i.Pts,
|
||||
&i.MediaJson,
|
||||
&i.MediaUnread,
|
||||
&i.ReactionUnread,
|
||||
&i.ViaBotID,
|
||||
&i.GroupedID,
|
||||
&i.Effect,
|
||||
&i.ReplyMarkupJson,
|
||||
&i.RichMessageJson,
|
||||
&i.Pinned,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listSavedDialogTops = `-- name: ListSavedDialogTops :many
|
||||
|
||||
WITH tops AS (
|
||||
SELECT m.saved_peer_type, m.saved_peer_id, MAX(m.box_id) AS top_box_id
|
||||
FROM message_boxes m
|
||||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = 'user'
|
||||
AND m.peer_id = $1::bigint
|
||||
AND NOT m.deleted
|
||||
AND m.saved_peer_type <> ''
|
||||
GROUP BY m.saved_peer_type, m.saved_peer_id
|
||||
)
|
||||
SELECT
|
||||
t.saved_peer_type AS dialog_peer_type,
|
||||
t.saved_peer_id AS dialog_peer_id,
|
||||
(p.user_id IS NOT NULL)::boolean AS dialog_pinned,
|
||||
m.box_id,
|
||||
m.private_message_id,
|
||||
m.owner_user_id,
|
||||
m.peer_type,
|
||||
m.peer_id,
|
||||
m.from_user_id,
|
||||
m.message_date,
|
||||
m.ttl_period,
|
||||
m.expires_at,
|
||||
m.edit_date,
|
||||
m.outgoing,
|
||||
m.body,
|
||||
m.entities::text AS entities_json,
|
||||
m.silent,
|
||||
m.noforwards,
|
||||
m.reply_to_msg_id,
|
||||
m.reply_to_peer_type,
|
||||
m.reply_to_peer_id,
|
||||
m.reply_to_top_id,
|
||||
m.reply_to_story_id,
|
||||
m.quote_text,
|
||||
m.quote_entities::text AS quote_entities_json,
|
||||
m.quote_offset,
|
||||
m.fwd_from_peer_type,
|
||||
m.fwd_from_peer_id,
|
||||
m.fwd_from_name,
|
||||
m.fwd_date,
|
||||
m.fwd_saved_from_peer_type,
|
||||
m.fwd_saved_from_peer_id,
|
||||
m.fwd_saved_from_msg_id,
|
||||
m.saved_peer_type,
|
||||
m.saved_peer_id,
|
||||
m.pts,
|
||||
m.media::text AS media_json,
|
||||
m.media_unread,
|
||||
m.reaction_unread,
|
||||
m.via_bot_id,
|
||||
m.grouped_id,
|
||||
m.effect,
|
||||
m.reply_markup::text AS reply_markup_json,
|
||||
m.rich_message::text AS rich_message_json,
|
||||
m.pinned
|
||||
FROM tops t
|
||||
JOIN message_boxes m
|
||||
ON m.owner_user_id = $1::bigint
|
||||
AND m.box_id = t.top_box_id
|
||||
LEFT JOIN saved_dialog_pins p
|
||||
ON p.user_id = $1::bigint
|
||||
AND p.peer_type = t.saved_peer_type
|
||||
AND p.peer_id = t.saved_peer_id
|
||||
WHERE ($2::int <= 0 OR t.top_box_id < $2::int)
|
||||
AND (NOT $3::boolean OR p.user_id IS NULL)
|
||||
ORDER BY t.top_box_id DESC
|
||||
LIMIT $4::int
|
||||
`
|
||||
|
||||
type ListSavedDialogTopsParams struct {
|
||||
OwnerUserID int64
|
||||
OffsetID int32
|
||||
ExcludePinned bool
|
||||
LimitCount int32
|
||||
}
|
||||
|
||||
type ListSavedDialogTopsRow struct {
|
||||
DialogPeerType string
|
||||
DialogPeerID int64
|
||||
DialogPinned bool
|
||||
BoxID int32
|
||||
PrivateMessageID int64
|
||||
OwnerUserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
FromUserID int64
|
||||
MessageDate int32
|
||||
TtlPeriod int32
|
||||
ExpiresAt int32
|
||||
EditDate int32
|
||||
Outgoing bool
|
||||
Body string
|
||||
EntitiesJson string
|
||||
Silent bool
|
||||
Noforwards bool
|
||||
ReplyToMsgID int32
|
||||
ReplyToPeerType string
|
||||
ReplyToPeerID int64
|
||||
ReplyToTopID int32
|
||||
ReplyToStoryID int32
|
||||
QuoteText string
|
||||
QuoteEntitiesJson string
|
||||
QuoteOffset int32
|
||||
FwdFromPeerType string
|
||||
FwdFromPeerID int64
|
||||
FwdFromName string
|
||||
FwdDate int32
|
||||
FwdSavedFromPeerType string
|
||||
FwdSavedFromPeerID int64
|
||||
FwdSavedFromMsgID int32
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
Pts int32
|
||||
MediaJson string
|
||||
MediaUnread bool
|
||||
ReactionUnread bool
|
||||
ViaBotID int64
|
||||
GroupedID int64
|
||||
Effect int64
|
||||
ReplyMarkupJson string
|
||||
RichMessageJson string
|
||||
Pinned bool
|
||||
}
|
||||
|
||||
// Saved Messages 分会话(saved dialogs)查询组。
|
||||
// 子会话 = self-chat box 行按 saved_peer 分组;top message 不物化,由
|
||||
// MAX(box_id) 聚合现算(box_id 单调于时间,date 序与 id 序一致),
|
||||
// 删除/清史后的一致性由查询本身保证。
|
||||
func (q *Queries) ListSavedDialogTops(ctx context.Context, arg ListSavedDialogTopsParams) ([]ListSavedDialogTopsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listSavedDialogTops,
|
||||
arg.OwnerUserID,
|
||||
arg.OffsetID,
|
||||
arg.ExcludePinned,
|
||||
arg.LimitCount,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListSavedDialogTopsRow
|
||||
for rows.Next() {
|
||||
var i ListSavedDialogTopsRow
|
||||
if err := rows.Scan(
|
||||
&i.DialogPeerType,
|
||||
&i.DialogPeerID,
|
||||
&i.DialogPinned,
|
||||
&i.BoxID,
|
||||
&i.PrivateMessageID,
|
||||
&i.OwnerUserID,
|
||||
&i.PeerType,
|
||||
&i.PeerID,
|
||||
&i.FromUserID,
|
||||
&i.MessageDate,
|
||||
&i.TtlPeriod,
|
||||
&i.ExpiresAt,
|
||||
&i.EditDate,
|
||||
&i.Outgoing,
|
||||
&i.Body,
|
||||
&i.EntitiesJson,
|
||||
&i.Silent,
|
||||
&i.Noforwards,
|
||||
&i.ReplyToMsgID,
|
||||
&i.ReplyToPeerType,
|
||||
&i.ReplyToPeerID,
|
||||
&i.ReplyToTopID,
|
||||
&i.ReplyToStoryID,
|
||||
&i.QuoteText,
|
||||
&i.QuoteEntitiesJson,
|
||||
&i.QuoteOffset,
|
||||
&i.FwdFromPeerType,
|
||||
&i.FwdFromPeerID,
|
||||
&i.FwdFromName,
|
||||
&i.FwdDate,
|
||||
&i.FwdSavedFromPeerType,
|
||||
&i.FwdSavedFromPeerID,
|
||||
&i.FwdSavedFromMsgID,
|
||||
&i.SavedPeerType,
|
||||
&i.SavedPeerID,
|
||||
&i.Pts,
|
||||
&i.MediaJson,
|
||||
&i.MediaUnread,
|
||||
&i.ReactionUnread,
|
||||
&i.ViaBotID,
|
||||
&i.GroupedID,
|
||||
&i.Effect,
|
||||
&i.ReplyMarkupJson,
|
||||
&i.RichMessageJson,
|
||||
&i.Pinned,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listSavedDialogTopsByPeers = `-- name: ListSavedDialogTopsByPeers :many
|
||||
WITH requested AS (
|
||||
SELECT
|
||||
($2::text[])[i] AS peer_type,
|
||||
($3::bigint[])[i] AS peer_id
|
||||
FROM generate_subscripts($3::bigint[], 1) AS g(i)
|
||||
WHERE i <= cardinality($2::text[])
|
||||
),
|
||||
tops AS (
|
||||
SELECT m.saved_peer_type, m.saved_peer_id, MAX(m.box_id) AS top_box_id
|
||||
FROM message_boxes m
|
||||
JOIN requested r
|
||||
ON r.peer_type = m.saved_peer_type
|
||||
AND r.peer_id = m.saved_peer_id
|
||||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = 'user'
|
||||
AND m.peer_id = $1::bigint
|
||||
AND NOT m.deleted
|
||||
GROUP BY m.saved_peer_type, m.saved_peer_id
|
||||
)
|
||||
SELECT
|
||||
t.saved_peer_type AS dialog_peer_type,
|
||||
t.saved_peer_id AS dialog_peer_id,
|
||||
(p.user_id IS NOT NULL)::boolean AS dialog_pinned,
|
||||
m.box_id,
|
||||
m.private_message_id,
|
||||
m.owner_user_id,
|
||||
m.peer_type,
|
||||
m.peer_id,
|
||||
m.from_user_id,
|
||||
m.message_date,
|
||||
m.ttl_period,
|
||||
m.expires_at,
|
||||
m.edit_date,
|
||||
m.outgoing,
|
||||
m.body,
|
||||
m.entities::text AS entities_json,
|
||||
m.silent,
|
||||
m.noforwards,
|
||||
m.reply_to_msg_id,
|
||||
m.reply_to_peer_type,
|
||||
m.reply_to_peer_id,
|
||||
m.reply_to_top_id,
|
||||
m.reply_to_story_id,
|
||||
m.quote_text,
|
||||
m.quote_entities::text AS quote_entities_json,
|
||||
m.quote_offset,
|
||||
m.fwd_from_peer_type,
|
||||
m.fwd_from_peer_id,
|
||||
m.fwd_from_name,
|
||||
m.fwd_date,
|
||||
m.fwd_saved_from_peer_type,
|
||||
m.fwd_saved_from_peer_id,
|
||||
m.fwd_saved_from_msg_id,
|
||||
m.saved_peer_type,
|
||||
m.saved_peer_id,
|
||||
m.pts,
|
||||
m.media::text AS media_json,
|
||||
m.media_unread,
|
||||
m.reaction_unread,
|
||||
m.via_bot_id,
|
||||
m.grouped_id,
|
||||
m.effect,
|
||||
m.reply_markup::text AS reply_markup_json,
|
||||
m.rich_message::text AS rich_message_json,
|
||||
m.pinned
|
||||
FROM tops t
|
||||
JOIN message_boxes m
|
||||
ON m.owner_user_id = $1::bigint
|
||||
AND m.box_id = t.top_box_id
|
||||
LEFT JOIN saved_dialog_pins p
|
||||
ON p.user_id = $1::bigint
|
||||
AND p.peer_type = t.saved_peer_type
|
||||
AND p.peer_id = t.saved_peer_id
|
||||
ORDER BY t.top_box_id DESC
|
||||
`
|
||||
|
||||
type ListSavedDialogTopsByPeersParams struct {
|
||||
OwnerUserID int64
|
||||
PeerTypes []string
|
||||
PeerIds []int64
|
||||
}
|
||||
|
||||
type ListSavedDialogTopsByPeersRow struct {
|
||||
DialogPeerType string
|
||||
DialogPeerID int64
|
||||
DialogPinned bool
|
||||
BoxID int32
|
||||
PrivateMessageID int64
|
||||
OwnerUserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
FromUserID int64
|
||||
MessageDate int32
|
||||
TtlPeriod int32
|
||||
ExpiresAt int32
|
||||
EditDate int32
|
||||
Outgoing bool
|
||||
Body string
|
||||
EntitiesJson string
|
||||
Silent bool
|
||||
Noforwards bool
|
||||
ReplyToMsgID int32
|
||||
ReplyToPeerType string
|
||||
ReplyToPeerID int64
|
||||
ReplyToTopID int32
|
||||
ReplyToStoryID int32
|
||||
QuoteText string
|
||||
QuoteEntitiesJson string
|
||||
QuoteOffset int32
|
||||
FwdFromPeerType string
|
||||
FwdFromPeerID int64
|
||||
FwdFromName string
|
||||
FwdDate int32
|
||||
FwdSavedFromPeerType string
|
||||
FwdSavedFromPeerID int64
|
||||
FwdSavedFromMsgID int32
|
||||
SavedPeerType string
|
||||
SavedPeerID int64
|
||||
Pts int32
|
||||
MediaJson string
|
||||
MediaUnread bool
|
||||
ReactionUnread bool
|
||||
ViaBotID int64
|
||||
GroupedID int64
|
||||
Effect int64
|
||||
ReplyMarkupJson string
|
||||
RichMessageJson string
|
||||
Pinned bool
|
||||
}
|
||||
|
||||
func (q *Queries) ListSavedDialogTopsByPeers(ctx context.Context, arg ListSavedDialogTopsByPeersParams) ([]ListSavedDialogTopsByPeersRow, error) {
|
||||
rows, err := q.db.Query(ctx, listSavedDialogTopsByPeers, arg.OwnerUserID, arg.PeerTypes, arg.PeerIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListSavedDialogTopsByPeersRow
|
||||
for rows.Next() {
|
||||
var i ListSavedDialogTopsByPeersRow
|
||||
if err := rows.Scan(
|
||||
&i.DialogPeerType,
|
||||
&i.DialogPeerID,
|
||||
&i.DialogPinned,
|
||||
&i.BoxID,
|
||||
&i.PrivateMessageID,
|
||||
&i.OwnerUserID,
|
||||
&i.PeerType,
|
||||
&i.PeerID,
|
||||
&i.FromUserID,
|
||||
&i.MessageDate,
|
||||
&i.TtlPeriod,
|
||||
&i.ExpiresAt,
|
||||
&i.EditDate,
|
||||
&i.Outgoing,
|
||||
&i.Body,
|
||||
&i.EntitiesJson,
|
||||
&i.Silent,
|
||||
&i.Noforwards,
|
||||
&i.ReplyToMsgID,
|
||||
&i.ReplyToPeerType,
|
||||
&i.ReplyToPeerID,
|
||||
&i.ReplyToTopID,
|
||||
&i.ReplyToStoryID,
|
||||
&i.QuoteText,
|
||||
&i.QuoteEntitiesJson,
|
||||
&i.QuoteOffset,
|
||||
&i.FwdFromPeerType,
|
||||
&i.FwdFromPeerID,
|
||||
&i.FwdFromName,
|
||||
&i.FwdDate,
|
||||
&i.FwdSavedFromPeerType,
|
||||
&i.FwdSavedFromPeerID,
|
||||
&i.FwdSavedFromMsgID,
|
||||
&i.SavedPeerType,
|
||||
&i.SavedPeerID,
|
||||
&i.Pts,
|
||||
&i.MediaJson,
|
||||
&i.MediaUnread,
|
||||
&i.ReactionUnread,
|
||||
&i.ViaBotID,
|
||||
&i.GroupedID,
|
||||
&i.Effect,
|
||||
&i.ReplyMarkupJson,
|
||||
&i.RichMessageJson,
|
||||
&i.Pinned,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const reorderSavedDialogPins = `-- name: ReorderSavedDialogPins :exec
|
||||
INSERT INTO saved_dialog_pins (user_id, peer_type, peer_id, pinned_order)
|
||||
SELECT
|
||||
$1::bigint,
|
||||
($2::text[])[i],
|
||||
($3::bigint[])[i],
|
||||
(i - 1)::int
|
||||
FROM generate_subscripts($3::bigint[], 1) AS g(i)
|
||||
WHERE i <= cardinality($2::text[])
|
||||
ON CONFLICT (user_id, peer_type, peer_id) DO UPDATE SET pinned_order = EXCLUDED.pinned_order
|
||||
`
|
||||
|
||||
type ReorderSavedDialogPinsParams struct {
|
||||
UserID int64
|
||||
PeerTypes []string
|
||||
PeerIds []int64
|
||||
}
|
||||
|
||||
func (q *Queries) ReorderSavedDialogPins(ctx context.Context, arg ReorderSavedDialogPinsParams) error {
|
||||
_, err := q.db.Exec(ctx, reorderSavedDialogPins, arg.UserID, arg.PeerTypes, arg.PeerIds)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertSavedDialogPinFront = `-- name: UpsertSavedDialogPinFront :execrows
|
||||
INSERT INTO saved_dialog_pins (user_id, peer_type, peer_id, pinned_order)
|
||||
VALUES (
|
||||
$1::bigint,
|
||||
$2::text,
|
||||
$3::bigint,
|
||||
COALESCE((SELECT MIN(pinned_order) - 1 FROM saved_dialog_pins WHERE user_id = $1::bigint), 0)
|
||||
)
|
||||
ON CONFLICT (user_id, peer_type, peer_id) DO NOTHING
|
||||
`
|
||||
|
||||
type UpsertSavedDialogPinFrontParams struct {
|
||||
UserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertSavedDialogPinFront(ctx context.Context, arg UpsertSavedDialogPinFrontParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, upsertSavedDialogPinFront, arg.UserID, arg.PeerType, arg.PeerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue