chore: refresh gramsrv public release
This commit is contained in:
parent
75cebe8dbf
commit
70b6820474
1274 changed files with 378751 additions and 59919 deletions
|
|
@ -19,7 +19,7 @@ func (q *Queries) DeleteAuthorization(ctx context.Context, authKeyID int64) erro
|
|||
}
|
||||
|
||||
const getAuthorizationByAuthKey = `-- name: GetAuthorizationByAuthKey :one
|
||||
SELECT auth_key_id, user_id, hash, layer, device_model, platform, system_version, api_id, app_version, ip, created_at, active_at FROM authorizations WHERE auth_key_id = $1
|
||||
SELECT auth_key_id, user_id, hash, layer, device_model, platform, system_version, api_id, app_version, ip, created_at, active_at, password_pending FROM authorizations WHERE auth_key_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAuthorizationByAuthKey(ctx context.Context, authKeyID int64) (Authorization, error) {
|
||||
|
|
@ -38,12 +38,13 @@ func (q *Queries) GetAuthorizationByAuthKey(ctx context.Context, authKeyID int64
|
|||
&i.Ip,
|
||||
&i.CreatedAt,
|
||||
&i.ActiveAt,
|
||||
&i.PasswordPending,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAuthorizationsByUser = `-- name: ListAuthorizationsByUser :many
|
||||
SELECT auth_key_id, user_id, hash, layer, device_model, platform, system_version, api_id, app_version, ip, created_at, active_at FROM authorizations
|
||||
SELECT auth_key_id, user_id, hash, layer, device_model, platform, system_version, api_id, app_version, ip, created_at, active_at, password_pending FROM authorizations
|
||||
WHERE user_id = $1
|
||||
ORDER BY active_at DESC, auth_key_id DESC
|
||||
`
|
||||
|
|
@ -70,6 +71,7 @@ func (q *Queries) ListAuthorizationsByUser(ctx context.Context, userID int64) ([
|
|||
&i.Ip,
|
||||
&i.CreatedAt,
|
||||
&i.ActiveAt,
|
||||
&i.PasswordPending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
440
internal/store/postgres/sqlcgen/bot.sql.go
Normal file
440
internal/store/postgres/sqlcgen/bot.sql.go
Normal file
|
|
@ -0,0 +1,440 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: bot.sql
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const allowBotSendMessage = `-- name: AllowBotSendMessage :one
|
||||
WITH inserted AS (
|
||||
INSERT INTO bot_user_permissions (bot_user_id, user_id, from_request)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (bot_user_id, user_id) DO NOTHING
|
||||
RETURNING 1
|
||||
),
|
||||
updated AS (
|
||||
UPDATE bot_user_permissions
|
||||
SET from_request = bot_user_permissions.from_request OR $3,
|
||||
updated_at = now()
|
||||
WHERE bot_user_id = $1 AND user_id = $2
|
||||
AND NOT EXISTS (SELECT 1 FROM inserted)
|
||||
AND $3
|
||||
AND NOT from_request
|
||||
RETURNING 1
|
||||
)
|
||||
SELECT EXISTS (SELECT 1 FROM inserted) AS created
|
||||
`
|
||||
|
||||
type AllowBotSendMessageParams struct {
|
||||
BotUserID int64
|
||||
UserID int64
|
||||
FromRequest bool
|
||||
}
|
||||
|
||||
func (q *Queries) AllowBotSendMessage(ctx context.Context, arg AllowBotSendMessageParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, allowBotSendMessage, arg.BotUserID, arg.UserID, arg.FromRequest)
|
||||
var created bool
|
||||
err := row.Scan(&created)
|
||||
return created, err
|
||||
}
|
||||
|
||||
const bumpBotInfoVersion = `-- name: BumpBotInfoVersion :one
|
||||
UPDATE users
|
||||
SET bot_info_version = bot_info_version + 1, updated_at = now()
|
||||
WHERE id = $1 AND is_bot
|
||||
RETURNING bot_info_version
|
||||
`
|
||||
|
||||
func (q *Queries) BumpBotInfoVersion(ctx context.Context, id int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, bumpBotInfoVersion, id)
|
||||
var bot_info_version int32
|
||||
err := row.Scan(&bot_info_version)
|
||||
return bot_info_version, err
|
||||
}
|
||||
|
||||
const canBotSendMessage = `-- name: CanBotSendMessage :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM bot_user_permissions
|
||||
WHERE bot_user_id = $1 AND user_id = $2
|
||||
)
|
||||
`
|
||||
|
||||
type CanBotSendMessageParams struct {
|
||||
BotUserID int64
|
||||
UserID int64
|
||||
}
|
||||
|
||||
func (q *Queries) CanBotSendMessage(ctx context.Context, arg CanBotSendMessageParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, canBotSendMessage, arg.BotUserID, arg.UserID)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
return exists, err
|
||||
}
|
||||
|
||||
const countBotsByOwner = `-- name: CountBotsByOwner :one
|
||||
SELECT COUNT(*) FROM bots WHERE owner_user_id = $1 AND bot_user_id <> owner_user_id
|
||||
`
|
||||
|
||||
func (q *Queries) CountBotsByOwner(ctx context.Context, ownerUserID int64) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countBotsByOwner, ownerUserID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const deleteBotChatState = `-- name: DeleteBotChatState :exec
|
||||
DELETE FROM bot_chat_states WHERE bot_user_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type DeleteBotChatStateParams struct {
|
||||
BotUserID int64
|
||||
UserID int64
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteBotChatState(ctx context.Context, arg DeleteBotChatStateParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteBotChatState, arg.BotUserID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getBot = `-- name: GetBot :one
|
||||
SELECT bot_user_id, owner_user_id, token_secret, description, commands, bot_chat_history, bot_nochats, inline_placeholder, created_at, updated_at, menu_button_type, menu_button_text, menu_button_url, bot_inline_geo FROM bots WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBot(ctx context.Context, botUserID int64) (Bot, error) {
|
||||
row := q.db.QueryRow(ctx, getBot, botUserID)
|
||||
var i Bot
|
||||
err := row.Scan(
|
||||
&i.BotUserID,
|
||||
&i.OwnerUserID,
|
||||
&i.TokenSecret,
|
||||
&i.Description,
|
||||
&i.Commands,
|
||||
&i.BotChatHistory,
|
||||
&i.BotNochats,
|
||||
&i.InlinePlaceholder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.MenuButtonType,
|
||||
&i.MenuButtonText,
|
||||
&i.MenuButtonUrl,
|
||||
&i.BotInlineGeo,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBotChatState = `-- name: GetBotChatState :one
|
||||
SELECT bot_user_id, user_id, state, updated_at FROM bot_chat_states WHERE bot_user_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type GetBotChatStateParams struct {
|
||||
BotUserID int64
|
||||
UserID int64
|
||||
}
|
||||
|
||||
func (q *Queries) GetBotChatState(ctx context.Context, arg GetBotChatStateParams) (BotChatState, error) {
|
||||
row := q.db.QueryRow(ctx, getBotChatState, arg.BotUserID, arg.UserID)
|
||||
var i BotChatState
|
||||
err := row.Scan(
|
||||
&i.BotUserID,
|
||||
&i.UserID,
|
||||
&i.State,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertBot = `-- name: InsertBot :exec
|
||||
INSERT INTO bots (bot_user_id, owner_user_id, token_secret)
|
||||
VALUES ($1, $2, $3)
|
||||
`
|
||||
|
||||
type InsertBotParams struct {
|
||||
BotUserID int64
|
||||
OwnerUserID int64
|
||||
TokenSecret string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertBot(ctx context.Context, arg InsertBotParams) error {
|
||||
_, err := q.db.Exec(ctx, insertBot, arg.BotUserID, arg.OwnerUserID, arg.TokenSecret)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertBotUser = `-- name: InsertBotUser :one
|
||||
INSERT INTO users (access_hash, phone, first_name, last_name, username, country_code, is_bot, bot_info_version)
|
||||
VALUES ($1, '', $2, '', $3, '', TRUE, 1)
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type InsertBotUserParams struct {
|
||||
AccessHash int64
|
||||
FirstName string
|
||||
Username string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertBotUser(ctx context.Context, arg InsertBotUserParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, insertBotUser, arg.AccessHash, arg.FirstName, arg.Username)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBotsByOwner = `-- name: ListBotsByOwner :many
|
||||
SELECT bot_user_id, owner_user_id, token_secret, description, commands, bot_chat_history, bot_nochats, inline_placeholder, created_at, updated_at, menu_button_type, menu_button_text, menu_button_url, bot_inline_geo FROM bots WHERE owner_user_id = $1 AND bot_user_id <> owner_user_id ORDER BY bot_user_id
|
||||
`
|
||||
|
||||
// 排除 self-owner 种子行(内置 BotFather 自有),与 memory 实现一致:/mybots 与
|
||||
// 创建上限只统计用户经 /newbot 创建的 bot。
|
||||
func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID int64) ([]Bot, error) {
|
||||
rows, err := q.db.Query(ctx, listBotsByOwner, ownerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Bot
|
||||
for rows.Next() {
|
||||
var i Bot
|
||||
if err := rows.Scan(
|
||||
&i.BotUserID,
|
||||
&i.OwnerUserID,
|
||||
&i.TokenSecret,
|
||||
&i.Description,
|
||||
&i.Commands,
|
||||
&i.BotChatHistory,
|
||||
&i.BotNochats,
|
||||
&i.InlinePlaceholder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.MenuButtonType,
|
||||
&i.MenuButtonText,
|
||||
&i.MenuButtonUrl,
|
||||
&i.BotInlineGeo,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setBotChatHistoryRow = `-- name: SetBotChatHistoryRow :execrows
|
||||
UPDATE bots SET bot_chat_history = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type SetBotChatHistoryRowParams struct {
|
||||
BotUserID int64
|
||||
BotChatHistory bool
|
||||
}
|
||||
|
||||
func (q *Queries) SetBotChatHistoryRow(ctx context.Context, arg SetBotChatHistoryRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setBotChatHistoryRow, arg.BotUserID, arg.BotChatHistory)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const setBotInlineGeoRow = `-- name: SetBotInlineGeoRow :execrows
|
||||
UPDATE bots SET bot_inline_geo = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type SetBotInlineGeoRowParams struct {
|
||||
BotUserID int64
|
||||
BotInlineGeo bool
|
||||
}
|
||||
|
||||
func (q *Queries) SetBotInlineGeoRow(ctx context.Context, arg SetBotInlineGeoRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setBotInlineGeoRow, arg.BotUserID, arg.BotInlineGeo)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const setBotInlinePlaceholderRow = `-- name: SetBotInlinePlaceholderRow :execrows
|
||||
UPDATE bots SET inline_placeholder = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type SetBotInlinePlaceholderRowParams struct {
|
||||
BotUserID int64
|
||||
InlinePlaceholder string
|
||||
}
|
||||
|
||||
func (q *Queries) SetBotInlinePlaceholderRow(ctx context.Context, arg SetBotInlinePlaceholderRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setBotInlinePlaceholderRow, arg.BotUserID, arg.InlinePlaceholder)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const setBotNochatsRow = `-- name: SetBotNochatsRow :execrows
|
||||
UPDATE bots SET bot_nochats = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type SetBotNochatsRowParams struct {
|
||||
BotUserID int64
|
||||
BotNochats bool
|
||||
}
|
||||
|
||||
func (q *Queries) SetBotNochatsRow(ctx context.Context, arg SetBotNochatsRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setBotNochatsRow, arg.BotUserID, arg.BotNochats)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateBotCommandsRow = `-- name: UpdateBotCommandsRow :execrows
|
||||
UPDATE bots SET commands = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type UpdateBotCommandsRowParams struct {
|
||||
BotUserID int64
|
||||
Commands []byte
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBotCommandsRow(ctx context.Context, arg UpdateBotCommandsRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateBotCommandsRow, arg.BotUserID, arg.Commands)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateBotDescriptionRow = `-- name: UpdateBotDescriptionRow :execrows
|
||||
UPDATE bots SET description = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type UpdateBotDescriptionRowParams struct {
|
||||
BotUserID int64
|
||||
Description string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBotDescriptionRow(ctx context.Context, arg UpdateBotDescriptionRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateBotDescriptionRow, arg.BotUserID, arg.Description)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateBotMenuButtonRow = `-- name: UpdateBotMenuButtonRow :execrows
|
||||
UPDATE bots
|
||||
SET menu_button_type = $2, menu_button_text = $3, menu_button_url = $4, updated_at = now()
|
||||
WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type UpdateBotMenuButtonRowParams struct {
|
||||
BotUserID int64
|
||||
MenuButtonType int16
|
||||
MenuButtonText string
|
||||
MenuButtonUrl string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBotMenuButtonRow(ctx context.Context, arg UpdateBotMenuButtonRowParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateBotMenuButtonRow,
|
||||
arg.BotUserID,
|
||||
arg.MenuButtonType,
|
||||
arg.MenuButtonText,
|
||||
arg.MenuButtonUrl,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateBotProfileFields = `-- name: UpdateBotProfileFields :one
|
||||
UPDATE users
|
||||
SET first_name = COALESCE($2, first_name),
|
||||
about = COALESCE($3, about),
|
||||
updated_at = now()
|
||||
WHERE id = $1 AND is_bot
|
||||
RETURNING bot_info_version
|
||||
`
|
||||
|
||||
type UpdateBotProfileFieldsParams struct {
|
||||
ID int64
|
||||
FirstName *string
|
||||
About *string
|
||||
}
|
||||
|
||||
// 部分更新 bot 的 users 行(setBotInfo 的 name/about);NULL 参数表示不动该字段。
|
||||
func (q *Queries) UpdateBotProfileFields(ctx context.Context, arg UpdateBotProfileFieldsParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, updateBotProfileFields, arg.ID, arg.FirstName, arg.About)
|
||||
var bot_info_version int32
|
||||
err := row.Scan(&bot_info_version)
|
||||
return bot_info_version, err
|
||||
}
|
||||
|
||||
const updateBotTokenSecret = `-- name: UpdateBotTokenSecret :execrows
|
||||
UPDATE bots SET token_secret = $2, updated_at = now() WHERE bot_user_id = $1
|
||||
`
|
||||
|
||||
type UpdateBotTokenSecretParams struct {
|
||||
BotUserID int64
|
||||
TokenSecret string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBotTokenSecret(ctx context.Context, arg UpdateBotTokenSecretParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateBotTokenSecret, arg.BotUserID, arg.TokenSecret)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const upsertBotChatState = `-- name: UpsertBotChatState :exec
|
||||
INSERT INTO bot_chat_states (bot_user_id, user_id, state, updated_at)
|
||||
VALUES ($1, $2, $3, now())
|
||||
ON CONFLICT (bot_user_id, user_id) DO UPDATE SET state = EXCLUDED.state, updated_at = now()
|
||||
`
|
||||
|
||||
type UpsertBotChatStateParams struct {
|
||||
BotUserID int64
|
||||
UserID int64
|
||||
State []byte
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertBotChatState(ctx context.Context, arg UpsertBotChatStateParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertBotChatState, arg.BotUserID, arg.UserID, arg.State)
|
||||
return err
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ package sqlcgen
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteContacts = `-- name: DeleteContacts :one
|
||||
|
|
@ -45,6 +47,7 @@ const getContact = `-- name: GetContact :one
|
|||
SELECT
|
||||
c.contact_user_id,
|
||||
c.mutual,
|
||||
c.close_friend,
|
||||
c.contact_phone,
|
||||
c.contact_first_name,
|
||||
c.contact_last_name,
|
||||
|
|
@ -59,6 +62,11 @@ SELECT
|
|||
u.country_code,
|
||||
u.verified,
|
||||
u.support,
|
||||
u.is_bot,
|
||||
u.bot_info_version,
|
||||
u.premium_expires_at,
|
||||
u.emoji_status_document_id,
|
||||
u.emoji_status_until,
|
||||
u.last_seen_at
|
||||
FROM contacts c
|
||||
JOIN users u ON u.id = c.contact_user_id
|
||||
|
|
@ -72,23 +80,29 @@ type GetContactParams struct {
|
|||
}
|
||||
|
||||
type GetContactRow struct {
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
LastSeenAt int64
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
CloseFriend bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
IsBot bool
|
||||
BotInfoVersion int32
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
EmojiStatusDocumentID int64
|
||||
EmojiStatusUntil int64
|
||||
LastSeenAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) GetContact(ctx context.Context, arg GetContactParams) (GetContactRow, error) {
|
||||
|
|
@ -97,6 +111,7 @@ func (q *Queries) GetContact(ctx context.Context, arg GetContactParams) (GetCont
|
|||
err := row.Scan(
|
||||
&i.ContactUserID,
|
||||
&i.Mutual,
|
||||
&i.CloseFriend,
|
||||
&i.ContactPhone,
|
||||
&i.ContactFirstName,
|
||||
&i.ContactLastName,
|
||||
|
|
@ -111,6 +126,11 @@ func (q *Queries) GetContact(ctx context.Context, arg GetContactParams) (GetCont
|
|||
&i.CountryCode,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.LastSeenAt,
|
||||
)
|
||||
return i, err
|
||||
|
|
@ -120,6 +140,7 @@ const listContactsByUser = `-- name: ListContactsByUser :many
|
|||
SELECT
|
||||
c.contact_user_id,
|
||||
c.mutual,
|
||||
c.close_friend,
|
||||
c.contact_phone,
|
||||
c.contact_first_name,
|
||||
c.contact_last_name,
|
||||
|
|
@ -134,6 +155,11 @@ SELECT
|
|||
u.country_code,
|
||||
u.verified,
|
||||
u.support,
|
||||
u.is_bot,
|
||||
u.bot_info_version,
|
||||
u.premium_expires_at,
|
||||
u.emoji_status_document_id,
|
||||
u.emoji_status_until,
|
||||
u.last_seen_at
|
||||
FROM contacts c
|
||||
JOIN users u ON u.id = c.contact_user_id
|
||||
|
|
@ -142,23 +168,29 @@ ORDER BY c.contact_first_name, c.contact_last_name, u.first_name, u.last_name, u
|
|||
`
|
||||
|
||||
type ListContactsByUserRow struct {
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
LastSeenAt int64
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
CloseFriend bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
IsBot bool
|
||||
BotInfoVersion int32
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
EmojiStatusDocumentID int64
|
||||
EmojiStatusUntil int64
|
||||
LastSeenAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) ListContactsByUser(ctx context.Context, userID int64) ([]ListContactsByUserRow, error) {
|
||||
|
|
@ -173,6 +205,7 @@ func (q *Queries) ListContactsByUser(ctx context.Context, userID int64) ([]ListC
|
|||
if err := rows.Scan(
|
||||
&i.ContactUserID,
|
||||
&i.Mutual,
|
||||
&i.CloseFriend,
|
||||
&i.ContactPhone,
|
||||
&i.ContactFirstName,
|
||||
&i.ContactLastName,
|
||||
|
|
@ -187,6 +220,11 @@ func (q *Queries) ListContactsByUser(ctx context.Context, userID int64) ([]ListC
|
|||
&i.CountryCode,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.LastSeenAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -207,11 +245,12 @@ WITH updated AS (
|
|||
updated_at = now()
|
||||
WHERE c.user_id = $3::bigint
|
||||
AND c.contact_user_id = $4::bigint
|
||||
RETURNING user_id, contact_user_id, mutual, created_at, updated_at, contact_phone, contact_first_name, contact_last_name, note, note_entities, close_friend, stories_hidden
|
||||
RETURNING user_id, contact_user_id, mutual, created_at, updated_at, contact_phone, contact_first_name, contact_last_name, note, note_entities, close_friend, stories_hidden, personal_photo_id, personal_photo_date
|
||||
)
|
||||
SELECT
|
||||
c.contact_user_id,
|
||||
c.mutual,
|
||||
c.close_friend,
|
||||
c.contact_phone,
|
||||
c.contact_first_name,
|
||||
c.contact_last_name,
|
||||
|
|
@ -226,6 +265,11 @@ SELECT
|
|||
u.country_code,
|
||||
u.verified,
|
||||
u.support,
|
||||
u.is_bot,
|
||||
u.bot_info_version,
|
||||
u.premium_expires_at,
|
||||
u.emoji_status_document_id,
|
||||
u.emoji_status_until,
|
||||
u.last_seen_at
|
||||
FROM updated c
|
||||
JOIN users u ON u.id = c.contact_user_id
|
||||
|
|
@ -239,23 +283,29 @@ type UpdateContactNoteParams struct {
|
|||
}
|
||||
|
||||
type UpdateContactNoteRow struct {
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
LastSeenAt int64
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
CloseFriend bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
IsBot bool
|
||||
BotInfoVersion int32
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
EmojiStatusDocumentID int64
|
||||
EmojiStatusUntil int64
|
||||
LastSeenAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateContactNote(ctx context.Context, arg UpdateContactNoteParams) (UpdateContactNoteRow, error) {
|
||||
|
|
@ -269,6 +319,7 @@ func (q *Queries) UpdateContactNote(ctx context.Context, arg UpdateContactNotePa
|
|||
err := row.Scan(
|
||||
&i.ContactUserID,
|
||||
&i.Mutual,
|
||||
&i.CloseFriend,
|
||||
&i.ContactPhone,
|
||||
&i.ContactFirstName,
|
||||
&i.ContactLastName,
|
||||
|
|
@ -283,6 +334,11 @@ func (q *Queries) UpdateContactNote(ctx context.Context, arg UpdateContactNotePa
|
|||
&i.CountryCode,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.LastSeenAt,
|
||||
)
|
||||
return i, err
|
||||
|
|
@ -326,7 +382,7 @@ upserted AS (
|
|||
note_entities = EXCLUDED.note_entities,
|
||||
mutual = contacts.mutual OR EXCLUDED.mutual,
|
||||
updated_at = now()
|
||||
RETURNING user_id, contact_user_id, mutual, created_at, updated_at, contact_phone, contact_first_name, contact_last_name, note, note_entities, close_friend, stories_hidden
|
||||
RETURNING user_id, contact_user_id, mutual, created_at, updated_at, contact_phone, contact_first_name, contact_last_name, note, note_entities, close_friend, stories_hidden, personal_photo_id, personal_photo_date
|
||||
),
|
||||
reverse_updated AS (
|
||||
UPDATE contacts c
|
||||
|
|
@ -340,6 +396,7 @@ reverse_updated AS (
|
|||
SELECT
|
||||
c.contact_user_id,
|
||||
c.mutual,
|
||||
c.close_friend,
|
||||
c.contact_phone,
|
||||
c.contact_first_name,
|
||||
c.contact_last_name,
|
||||
|
|
@ -354,6 +411,11 @@ SELECT
|
|||
u.country_code,
|
||||
u.verified,
|
||||
u.support,
|
||||
u.is_bot,
|
||||
u.bot_info_version,
|
||||
u.premium_expires_at,
|
||||
u.emoji_status_document_id,
|
||||
u.emoji_status_until,
|
||||
u.last_seen_at,
|
||||
EXISTS (SELECT 1 FROM reverse_updated)::boolean AS reverse_mutual_changed
|
||||
FROM upserted c
|
||||
|
|
@ -371,24 +433,30 @@ type UpsertContactParams struct {
|
|||
}
|
||||
|
||||
type UpsertContactRow struct {
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
LastSeenAt int64
|
||||
ReverseMutualChanged bool
|
||||
ContactUserID int64
|
||||
Mutual bool
|
||||
CloseFriend bool
|
||||
ContactPhone string
|
||||
ContactFirstName string
|
||||
ContactLastName string
|
||||
Note string
|
||||
NoteEntitiesJson string
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
IsBot bool
|
||||
BotInfoVersion int32
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
EmojiStatusDocumentID int64
|
||||
EmojiStatusUntil int64
|
||||
LastSeenAt int64
|
||||
ReverseMutualChanged bool
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertContact(ctx context.Context, arg UpsertContactParams) (UpsertContactRow, error) {
|
||||
|
|
@ -405,6 +473,7 @@ func (q *Queries) UpsertContact(ctx context.Context, arg UpsertContactParams) (U
|
|||
err := row.Scan(
|
||||
&i.ContactUserID,
|
||||
&i.Mutual,
|
||||
&i.CloseFriend,
|
||||
&i.ContactPhone,
|
||||
&i.ContactFirstName,
|
||||
&i.ContactLastName,
|
||||
|
|
@ -419,6 +488,11 @@ func (q *Queries) UpsertContact(ctx context.Context, arg UpsertContactParams) (U
|
|||
&i.CountryCode,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.LastSeenAt,
|
||||
&i.ReverseMutualChanged,
|
||||
)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -7,6 +7,8 @@ package sqlcgen
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addProfilePhoto = `-- name: AddProfilePhoto :exec
|
||||
|
|
@ -197,10 +199,52 @@ func (q *Queries) DeactivateProfilePhotos(ctx context.Context, arg DeactivatePro
|
|||
return items, nil
|
||||
}
|
||||
|
||||
const deleteUploadParts = `-- name: DeleteUploadParts :exec
|
||||
const deleteExpiredUploadParts = `-- name: DeleteExpiredUploadParts :many
|
||||
WITH doomed AS (
|
||||
SELECT owner_user_id, file_id, part
|
||||
FROM upload_parts
|
||||
WHERE created_at < $1::timestamptz
|
||||
ORDER BY created_at ASC
|
||||
LIMIT $2::int
|
||||
)
|
||||
DELETE FROM upload_parts p
|
||||
USING doomed d
|
||||
WHERE p.owner_user_id = d.owner_user_id
|
||||
AND p.file_id = d.file_id
|
||||
AND p.part = d.part
|
||||
RETURNING p.object_key
|
||||
`
|
||||
|
||||
type DeleteExpiredUploadPartsParams struct {
|
||||
Before pgtype.Timestamptz
|
||||
BatchLimit int32
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteExpiredUploadParts(ctx context.Context, arg DeleteExpiredUploadPartsParams) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, deleteExpiredUploadParts, arg.Before, arg.BatchLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var object_key string
|
||||
if err := rows.Scan(&object_key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, object_key)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const deleteUploadParts = `-- name: DeleteUploadParts :many
|
||||
DELETE FROM upload_parts
|
||||
WHERE owner_user_id = $1::bigint
|
||||
AND file_id = $2::bigint
|
||||
RETURNING object_key
|
||||
`
|
||||
|
||||
type DeleteUploadPartsParams struct {
|
||||
|
|
@ -208,9 +252,24 @@ type DeleteUploadPartsParams struct {
|
|||
FileID int64
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUploadParts(ctx context.Context, arg DeleteUploadPartsParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteUploadParts, arg.OwnerUserID, arg.FileID)
|
||||
return err
|
||||
func (q *Queries) DeleteUploadParts(ctx context.Context, arg DeleteUploadPartsParams) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, deleteUploadParts, arg.OwnerUserID, arg.FileID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var object_key string
|
||||
if err := rows.Scan(&object_key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, object_key)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getDocument = `-- name: GetDocument :one
|
||||
|
|
@ -562,6 +621,71 @@ func (q *Queries) GetStickerSetBySystemKey(ctx context.Context, systemKey string
|
|||
return i, err
|
||||
}
|
||||
|
||||
const getUploadPartSlot = `-- name: GetUploadPartSlot :one
|
||||
SELECT
|
||||
COALESCE((
|
||||
SELECT size
|
||||
FROM upload_parts
|
||||
WHERE owner_user_id = $1::bigint
|
||||
AND file_id = $2::bigint
|
||||
AND part = $3::int
|
||||
), -1)::bigint AS existing_bytes,
|
||||
COALESCE((
|
||||
SELECT object_key
|
||||
FROM upload_parts
|
||||
WHERE owner_user_id = $1::bigint
|
||||
AND file_id = $2::bigint
|
||||
AND part = $3::int
|
||||
), '')::text AS object_key,
|
||||
(
|
||||
SELECT COUNT(*)::int
|
||||
FROM upload_parts
|
||||
WHERE owner_user_id = $1::bigint
|
||||
AND file_id = $2::bigint
|
||||
)::int AS file_parts
|
||||
`
|
||||
|
||||
type GetUploadPartSlotParams struct {
|
||||
OwnerUserID int64
|
||||
FileID int64
|
||||
Part int32
|
||||
}
|
||||
|
||||
type GetUploadPartSlotRow struct {
|
||||
ExistingBytes int64
|
||||
ObjectKey string
|
||||
FileParts int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetUploadPartSlot(ctx context.Context, arg GetUploadPartSlotParams) (GetUploadPartSlotRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUploadPartSlot, arg.OwnerUserID, arg.FileID, arg.Part)
|
||||
var i GetUploadPartSlotRow
|
||||
err := row.Scan(&i.ExistingBytes, &i.ObjectKey, &i.FileParts)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUploadPartUsage = `-- name: GetUploadPartUsage :one
|
||||
SELECT
|
||||
COALESCE(SUM(size), 0)::bigint AS bytes,
|
||||
COUNT(*)::int AS parts,
|
||||
COUNT(DISTINCT file_id)::int AS files
|
||||
FROM upload_parts
|
||||
WHERE owner_user_id = $1::bigint
|
||||
`
|
||||
|
||||
type GetUploadPartUsageRow struct {
|
||||
Bytes int64
|
||||
Parts int32
|
||||
Files int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetUploadPartUsage(ctx context.Context, ownerUserID int64) (GetUploadPartUsageRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUploadPartUsage, ownerUserID)
|
||||
var i GetUploadPartUsageRow
|
||||
err := row.Scan(&i.Bytes, &i.Parts, &i.Files)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAvailableReactions = `-- name: ListAvailableReactions :many
|
||||
SELECT
|
||||
reaction, title, inactive, premium,
|
||||
|
|
@ -732,7 +856,7 @@ func (q *Queries) ListStickerSetsByKind(ctx context.Context, setKind string) ([]
|
|||
}
|
||||
|
||||
const listUploadParts = `-- name: ListUploadParts :many
|
||||
SELECT part, total_parts, is_big, bytes
|
||||
SELECT part, total_parts, is_big, backend, object_key, size, sha256
|
||||
FROM upload_parts
|
||||
WHERE owner_user_id = $1::bigint
|
||||
AND file_id = $2::bigint
|
||||
|
|
@ -748,7 +872,10 @@ type ListUploadPartsRow struct {
|
|||
Part int32
|
||||
TotalParts int32
|
||||
IsBig bool
|
||||
Bytes []byte
|
||||
Backend string
|
||||
ObjectKey string
|
||||
Size int64
|
||||
Sha256 []byte
|
||||
}
|
||||
|
||||
func (q *Queries) ListUploadParts(ctx context.Context, arg ListUploadPartsParams) ([]ListUploadPartsRow, error) {
|
||||
|
|
@ -764,7 +891,10 @@ func (q *Queries) ListUploadParts(ctx context.Context, arg ListUploadPartsParams
|
|||
&i.Part,
|
||||
&i.TotalParts,
|
||||
&i.IsBig,
|
||||
&i.Bytes,
|
||||
&i.Backend,
|
||||
&i.ObjectKey,
|
||||
&i.Size,
|
||||
&i.Sha256,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1116,19 +1246,26 @@ func (q *Queries) PutStickerSet(ctx context.Context, arg PutStickerSetParams) er
|
|||
|
||||
const saveUploadPart = `-- name: SaveUploadPart :exec
|
||||
|
||||
INSERT INTO upload_parts (owner_user_id, file_id, part, total_parts, is_big, bytes)
|
||||
INSERT INTO upload_parts (owner_user_id, file_id, part, total_parts, is_big, backend, object_key, size, sha256)
|
||||
VALUES (
|
||||
$1::bigint,
|
||||
$2::bigint,
|
||||
$3::int,
|
||||
$4::int,
|
||||
$5::boolean,
|
||||
$6::bytea
|
||||
$6::text,
|
||||
$7::text,
|
||||
$8::bigint,
|
||||
$9::bytea
|
||||
)
|
||||
ON CONFLICT (owner_user_id, file_id, part) DO UPDATE SET
|
||||
total_parts = EXCLUDED.total_parts,
|
||||
is_big = EXCLUDED.is_big,
|
||||
bytes = EXCLUDED.bytes
|
||||
backend = EXCLUDED.backend,
|
||||
object_key = EXCLUDED.object_key,
|
||||
size = EXCLUDED.size,
|
||||
sha256 = EXCLUDED.sha256,
|
||||
created_at = now()
|
||||
`
|
||||
|
||||
type SaveUploadPartParams struct {
|
||||
|
|
@ -1137,7 +1274,10 @@ type SaveUploadPartParams struct {
|
|||
Part int32
|
||||
TotalParts int32
|
||||
IsBig bool
|
||||
Bytes []byte
|
||||
Backend string
|
||||
ObjectKey string
|
||||
Size int64
|
||||
Sha256 []byte
|
||||
}
|
||||
|
||||
// upload_parts ----------------------------------------------------------------
|
||||
|
|
@ -1148,7 +1288,10 @@ func (q *Queries) SaveUploadPart(ctx context.Context, arg SaveUploadPartParams)
|
|||
arg.Part,
|
||||
arg.TotalParts,
|
||||
arg.IsBig,
|
||||
arg.Bytes,
|
||||
arg.Backend,
|
||||
arg.ObjectKey,
|
||||
arg.Size,
|
||||
arg.Sha256,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
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
|
||||
}
|
||||
|
|
@ -9,6 +9,29 @@ import (
|
|||
"context"
|
||||
)
|
||||
|
||||
const deleteExpiredTempAuthKeys = `-- name: DeleteExpiredTempAuthKeys :execrows
|
||||
DELETE FROM auth_keys
|
||||
WHERE auth_key_id IN (
|
||||
SELECT temp_auth_key_id
|
||||
FROM temp_auth_key_bindings
|
||||
WHERE expires_at < $1
|
||||
LIMIT $2
|
||||
)
|
||||
`
|
||||
|
||||
type DeleteExpiredTempAuthKeysParams struct {
|
||||
ExpiresAt int32
|
||||
Limit int32
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteExpiredTempAuthKeys(ctx context.Context, arg DeleteExpiredTempAuthKeysParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteExpiredTempAuthKeys, arg.ExpiresAt, arg.Limit)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const getTempAuthKeyBinding = `-- name: GetTempAuthKeyBinding :one
|
||||
SELECT
|
||||
temp_auth_key_id,
|
||||
|
|
|
|||
|
|
@ -74,10 +74,10 @@ const upsertUpdateState = `-- name: UpsertUpdateState :exec
|
|||
INSERT INTO update_states (auth_key_id, user_id, pts, qts, date, seq)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (auth_key_id, user_id) DO UPDATE SET
|
||||
pts = EXCLUDED.pts,
|
||||
qts = EXCLUDED.qts,
|
||||
date = EXCLUDED.date,
|
||||
seq = EXCLUDED.seq,
|
||||
pts = GREATEST(update_states.pts, EXCLUDED.pts),
|
||||
qts = GREATEST(update_states.qts, EXCLUDED.qts),
|
||||
date = GREATEST(update_states.date, EXCLUDED.date),
|
||||
seq = GREATEST(update_states.seq, EXCLUDED.seq),
|
||||
updated_at = now()
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -7,21 +7,24 @@ package sqlcgen
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (access_hash, phone, first_name, last_name, username, country_code)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at
|
||||
INSERT INTO users (access_hash, phone, first_name, last_name, username, country_code, premium_expires_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
Username string
|
||||
CountryCode string
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
||||
|
|
@ -32,6 +35,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
|||
arg.LastName,
|
||||
arg.Username,
|
||||
arg.CountryCode,
|
||||
arg.PremiumExpiresAt,
|
||||
)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
|
|
@ -48,12 +52,28 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at FROM users WHERE id = $1
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) {
|
||||
|
|
@ -73,12 +93,28 @@ func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) {
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByPhone = `-- name: GetUserByPhone :one
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at FROM users WHERE phone = $1
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id FROM users WHERE phone = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByPhone(ctx context.Context, phone string) (User, error) {
|
||||
|
|
@ -98,12 +134,28 @@ func (q *Queries) GetUserByPhone(ctx context.Context, phone string) (User, error
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByUsername = `-- name: GetUserByUsername :one
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at FROM users WHERE lower(username) = lower($1) AND username <> ''
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id FROM users WHERE lower(username) = lower($1) AND username <> ''
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByUsername(ctx context.Context, lower string) (User, error) {
|
||||
|
|
@ -123,12 +175,28 @@ func (q *Queries) GetUserByUsername(ctx context.Context, lower string) (User, er
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUsersByIDs = `-- name: GetUsersByIDs :many
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
FROM users
|
||||
WHERE id = ANY($1::bigint[])
|
||||
ORDER BY id
|
||||
|
|
@ -157,6 +225,22 @@ func (q *Queries) GetUsersByIDs(ctx context.Context, ids []int64) ([]User, error
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -169,7 +253,7 @@ func (q *Queries) GetUsersByIDs(ctx context.Context, ids []int64) ([]User, error
|
|||
}
|
||||
|
||||
const getUsersByPhones = `-- name: GetUsersByPhones :many
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at
|
||||
SELECT id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
FROM users
|
||||
WHERE phone = ANY($1::text[])
|
||||
ORDER BY id
|
||||
|
|
@ -198,6 +282,22 @@ func (q *Queries) GetUsersByPhones(ctx context.Context, phones []string) ([]User
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -222,6 +322,17 @@ WITH matched AS (
|
|||
u.country_code,
|
||||
u.verified,
|
||||
u.support,
|
||||
u.is_bot,
|
||||
u.bot_info_version,
|
||||
u.premium_expires_at,
|
||||
u.emoji_status_document_id,
|
||||
u.emoji_status_until,
|
||||
u.color_set,
|
||||
u.color,
|
||||
u.color_background_emoji_id,
|
||||
u.profile_color_set,
|
||||
u.profile_color,
|
||||
u.profile_color_background_emoji_id,
|
||||
u.last_seen_at,
|
||||
(c.contact_user_id IS NOT NULL)::boolean AS contact,
|
||||
COALESCE(c.mutual, false)::boolean AS mutual,
|
||||
|
|
@ -259,6 +370,17 @@ SELECT
|
|||
country_code,
|
||||
verified,
|
||||
support,
|
||||
is_bot,
|
||||
bot_info_version,
|
||||
premium_expires_at,
|
||||
emoji_status_document_id,
|
||||
emoji_status_until,
|
||||
color_set,
|
||||
color,
|
||||
color_background_emoji_id,
|
||||
profile_color_set,
|
||||
profile_color,
|
||||
profile_color_background_emoji_id,
|
||||
last_seen_at,
|
||||
contact,
|
||||
mutual
|
||||
|
|
@ -276,19 +398,30 @@ type SearchUsersParams struct {
|
|||
}
|
||||
|
||||
type SearchUsersRow struct {
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
About string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
LastSeenAt int64
|
||||
Contact bool
|
||||
Mutual bool
|
||||
ID int64
|
||||
AccessHash int64
|
||||
Phone string
|
||||
FirstName string
|
||||
LastName string
|
||||
About string
|
||||
Username string
|
||||
CountryCode string
|
||||
Verified bool
|
||||
Support bool
|
||||
IsBot bool
|
||||
BotInfoVersion int32
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
EmojiStatusDocumentID int64
|
||||
EmojiStatusUntil int64
|
||||
ColorSet bool
|
||||
Color int32
|
||||
ColorBackgroundEmojiID int64
|
||||
ProfileColorSet bool
|
||||
ProfileColor int32
|
||||
ProfileColorBackgroundEmojiID int64
|
||||
LastSeenAt int64
|
||||
Contact bool
|
||||
Mutual bool
|
||||
}
|
||||
|
||||
func (q *Queries) SearchUsers(ctx context.Context, arg SearchUsersParams) ([]SearchUsersRow, error) {
|
||||
|
|
@ -317,6 +450,17 @@ func (q *Queries) SearchUsers(ctx context.Context, arg SearchUsersParams) ([]Sea
|
|||
&i.CountryCode,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.LastSeenAt,
|
||||
&i.Contact,
|
||||
&i.Mutual,
|
||||
|
|
@ -331,6 +475,345 @@ func (q *Queries) SearchUsers(ctx context.Context, arg SearchUsersParams) ([]Sea
|
|||
return items, nil
|
||||
}
|
||||
|
||||
const setUserPremiumUntil = `-- name: SetUserPremiumUntil :one
|
||||
UPDATE users
|
||||
SET premium_expires_at = $1::timestamptz,
|
||||
updated_at = now()
|
||||
WHERE id = $2::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type SetUserPremiumUntilParams struct {
|
||||
PremiumExpiresAt pgtype.Timestamptz
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) SetUserPremiumUntil(ctx context.Context, arg SetUserPremiumUntilParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, setUserPremiumUntil, arg.PremiumExpiresAt, arg.ID)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setUserVerified = `-- name: SetUserVerified :one
|
||||
UPDATE users
|
||||
SET verified = $1::boolean,
|
||||
updated_at = now()
|
||||
WHERE id = $2::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type SetUserVerifiedParams struct {
|
||||
Verified bool
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) SetUserVerified(ctx context.Context, arg SetUserVerifiedParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, setUserVerified, arg.Verified, arg.ID)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const sweepExpiredPremium = `-- name: SweepExpiredPremium :many
|
||||
UPDATE users
|
||||
SET premium_expires_at = NULL,
|
||||
updated_at = now()
|
||||
WHERE id IN (
|
||||
SELECT id FROM users
|
||||
WHERE premium_expires_at IS NOT NULL
|
||||
AND premium_expires_at <= $1::timestamptz
|
||||
ORDER BY premium_expires_at
|
||||
LIMIT $2::int
|
||||
)
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type SweepExpiredPremiumParams struct {
|
||||
Now pgtype.Timestamptz
|
||||
LimitCount int32
|
||||
}
|
||||
|
||||
func (q *Queries) SweepExpiredPremium(ctx context.Context, arg SweepExpiredPremiumParams) ([]User, error) {
|
||||
rows, err := q.db.Query(ctx, sweepExpiredPremium, arg.Now, arg.LimitCount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []User
|
||||
for rows.Next() {
|
||||
var i User
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateUserBirthday = `-- name: UpdateUserBirthday :one
|
||||
UPDATE users
|
||||
SET birthday_day = $1::int,
|
||||
birthday_month = $2::int,
|
||||
birthday_year = $3::int,
|
||||
updated_at = now()
|
||||
WHERE id = $4::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserBirthdayParams struct {
|
||||
BirthdayDay int32
|
||||
BirthdayMonth int32
|
||||
BirthdayYear int32
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserBirthday(ctx context.Context, arg UpdateUserBirthdayParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserBirthday,
|
||||
arg.BirthdayDay,
|
||||
arg.BirthdayMonth,
|
||||
arg.BirthdayYear,
|
||||
arg.ID,
|
||||
)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserColor = `-- name: UpdateUserColor :one
|
||||
UPDATE users
|
||||
SET color_set = $1::boolean,
|
||||
color = $2::int,
|
||||
color_background_emoji_id = $3::bigint,
|
||||
updated_at = now()
|
||||
WHERE id = $4::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserColorParams struct {
|
||||
ColorSet bool
|
||||
Color int32
|
||||
BackgroundEmojiID int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserColor(ctx context.Context, arg UpdateUserColorParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserColor,
|
||||
arg.ColorSet,
|
||||
arg.Color,
|
||||
arg.BackgroundEmojiID,
|
||||
arg.ID,
|
||||
)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserEmojiStatus = `-- name: UpdateUserEmojiStatus :one
|
||||
UPDATE users
|
||||
SET emoji_status_document_id = $1::bigint,
|
||||
emoji_status_until = $2::bigint,
|
||||
updated_at = now()
|
||||
WHERE id = $3::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserEmojiStatusParams struct {
|
||||
EmojiStatusDocumentID int64
|
||||
EmojiStatusUntil int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserEmojiStatus(ctx context.Context, arg UpdateUserEmojiStatusParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserEmojiStatus, arg.EmojiStatusDocumentID, arg.EmojiStatusUntil, arg.ID)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserLastSeen = `-- name: UpdateUserLastSeen :exec
|
||||
UPDATE users
|
||||
SET last_seen_at = GREATEST(last_seen_at, $1::bigint),
|
||||
|
|
@ -348,6 +831,56 @@ func (q *Queries) UpdateUserLastSeen(ctx context.Context, arg UpdateUserLastSeen
|
|||
return err
|
||||
}
|
||||
|
||||
const updateUserPersonalChannel = `-- name: UpdateUserPersonalChannel :one
|
||||
UPDATE users
|
||||
SET personal_channel_id = $1::bigint,
|
||||
updated_at = now()
|
||||
WHERE id = $2::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserPersonalChannelParams struct {
|
||||
PersonalChannelID int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserPersonalChannel(ctx context.Context, arg UpdateUserPersonalChannelParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserPersonalChannel, arg.PersonalChannelID, arg.ID)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserProfile = `-- name: UpdateUserProfile :one
|
||||
UPDATE users
|
||||
SET first_name = $2,
|
||||
|
|
@ -355,7 +888,7 @@ SET first_name = $2,
|
|||
about = $4,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserProfileParams struct {
|
||||
|
|
@ -387,6 +920,81 @@ func (q *Queries) UpdateUserProfile(ctx context.Context, arg UpdateUserProfilePa
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserProfileColor = `-- name: UpdateUserProfileColor :one
|
||||
UPDATE users
|
||||
SET profile_color_set = $1::boolean,
|
||||
profile_color = $2::int,
|
||||
profile_color_background_emoji_id = $3::bigint,
|
||||
updated_at = now()
|
||||
WHERE id = $4::bigint
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserProfileColorParams struct {
|
||||
ColorSet bool
|
||||
Color int32
|
||||
BackgroundEmojiID int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserProfileColor(ctx context.Context, arg UpdateUserProfileColorParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserProfileColor,
|
||||
arg.ColorSet,
|
||||
arg.Color,
|
||||
arg.BackgroundEmojiID,
|
||||
arg.ID,
|
||||
)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AccessHash,
|
||||
&i.Phone,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Username,
|
||||
&i.CountryCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Verified,
|
||||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
@ -396,7 +1004,7 @@ UPDATE users
|
|||
SET username = $2,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at
|
||||
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
|
||||
`
|
||||
|
||||
type UpdateUserUsernameParams struct {
|
||||
|
|
@ -421,6 +1029,22 @@ func (q *Queries) UpdateUserUsername(ctx context.Context, arg UpdateUserUsername
|
|||
&i.Support,
|
||||
&i.About,
|
||||
&i.LastSeenAt,
|
||||
&i.DefaultHistoryTtlPeriod,
|
||||
&i.IsBot,
|
||||
&i.BotInfoVersion,
|
||||
&i.PremiumExpiresAt,
|
||||
&i.EmojiStatusDocumentID,
|
||||
&i.EmojiStatusUntil,
|
||||
&i.ColorSet,
|
||||
&i.Color,
|
||||
&i.ColorBackgroundEmojiID,
|
||||
&i.ProfileColorSet,
|
||||
&i.ProfileColor,
|
||||
&i.ProfileColorBackgroundEmojiID,
|
||||
&i.BirthdayDay,
|
||||
&i.BirthdayMonth,
|
||||
&i.BirthdayYear,
|
||||
&i.PersonalChannelID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue