mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Each verified: the generated dbgen method's only references were the .sql definition and dbgen output itself (no wrapper in db/*.go, no test, no script). ArchiveChannel, DeleteAttachment, FindExistingDMChannel, GetDefaultRole, GetMessagesByChannel, GetMessagesByChannelBeforeCursor, GetMessagesForAPIBeforeCursor, GetPinnedMessageRows, GetPlugin, GetPluginByName, InsertDMChannel, InsertDMOpenState, InsertDMParticipants, LinkAttachmentToMessage, SetChannelMixingThreshold, SetChannelVoiceMaxVideo, SetChannelVoiceQuality, UpdateVoiceSpeaking. dbgen regenerated with the pinned sqlc v1.30.0 (132 → 114 queries); sqlc-verify clean; db/service/ws suites green including -race. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
159 lines
4.6 KiB
Go
159 lines
4.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: dm.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const closeDM = `-- name: CloseDM :exec
|
|
DELETE FROM dm_open_state WHERE user_id = ? AND channel_id = ?
|
|
`
|
|
|
|
type CloseDMParams struct {
|
|
UserID int64 `json:"userId"`
|
|
ChannelID int64 `json:"channelId"`
|
|
}
|
|
|
|
func (q *Queries) CloseDM(ctx context.Context, arg CloseDMParams) error {
|
|
_, err := q.db.ExecContext(ctx, closeDM, arg.UserID, arg.ChannelID)
|
|
return err
|
|
}
|
|
|
|
const getDMParticipantIDs = `-- name: GetDMParticipantIDs :many
|
|
SELECT user_id FROM dm_participants WHERE channel_id = ?
|
|
`
|
|
|
|
func (q *Queries) GetDMParticipantIDs(ctx context.Context, channelID int64) ([]int64, error) {
|
|
rows, err := q.db.QueryContext(ctx, getDMParticipantIDs, channelID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []int64{}
|
|
for rows.Next() {
|
|
var user_id int64
|
|
if err := rows.Scan(&user_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, user_id)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getUserDMChannels = `-- name: GetUserDMChannels :many
|
|
SELECT
|
|
c.id AS channel_id,
|
|
u.id AS recipient_id,
|
|
u.username AS recipient_username,
|
|
COALESCE(u.avatar, '') AS recipient_avatar,
|
|
u.status AS recipient_status,
|
|
lm.id AS last_message_id,
|
|
COALESCE(lm.content, '') AS last_message,
|
|
COALESCE(lm.timestamp, '') AS last_message_at,
|
|
COUNT(CASE WHEN m_unread.id > COALESCE(rs.last_message_id, 0)
|
|
AND m_unread.deleted = 0 THEN 1 END) AS unread_count
|
|
FROM dm_open_state dos
|
|
JOIN channels c ON c.id = dos.channel_id AND c.type = 'dm'
|
|
JOIN dm_participants dp ON dp.channel_id = c.id AND dp.user_id != ?
|
|
JOIN users u ON u.id = dp.user_id
|
|
LEFT JOIN messages lm ON lm.id = (
|
|
SELECT MAX(id) FROM messages WHERE channel_id = c.id AND deleted = 0
|
|
)
|
|
LEFT JOIN messages m_unread ON m_unread.channel_id = c.id
|
|
LEFT JOIN read_states rs ON rs.channel_id = c.id AND rs.user_id = ?
|
|
WHERE dos.user_id = ?
|
|
GROUP BY c.id
|
|
ORDER BY COALESCE(lm.timestamp, dos.opened_at) DESC
|
|
`
|
|
|
|
type GetUserDMChannelsParams struct {
|
|
UserID int64 `json:"userId"`
|
|
UserID_2 int64 `json:"userId2"`
|
|
UserID_3 int64 `json:"userId3"`
|
|
}
|
|
|
|
type GetUserDMChannelsRow struct {
|
|
ChannelID int64 `json:"channelId"`
|
|
RecipientID int64 `json:"recipientId"`
|
|
RecipientUsername string `json:"recipientUsername"`
|
|
RecipientAvatar string `json:"recipientAvatar"`
|
|
RecipientStatus string `json:"recipientStatus"`
|
|
LastMessageID *int64 `json:"lastMessageId"`
|
|
LastMessage string `json:"lastMessage"`
|
|
LastMessageAt string `json:"lastMessageAt"`
|
|
UnreadCount int64 `json:"unreadCount"`
|
|
}
|
|
|
|
func (q *Queries) GetUserDMChannels(ctx context.Context, arg GetUserDMChannelsParams) ([]GetUserDMChannelsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getUserDMChannels, arg.UserID, arg.UserID_2, arg.UserID_3)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetUserDMChannelsRow{}
|
|
for rows.Next() {
|
|
var i GetUserDMChannelsRow
|
|
if err := rows.Scan(
|
|
&i.ChannelID,
|
|
&i.RecipientID,
|
|
&i.RecipientUsername,
|
|
&i.RecipientAvatar,
|
|
&i.RecipientStatus,
|
|
&i.LastMessageID,
|
|
&i.LastMessage,
|
|
&i.LastMessageAt,
|
|
&i.UnreadCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const isDMParticipant = `-- name: IsDMParticipant :one
|
|
SELECT user_id FROM dm_participants WHERE user_id = ? AND channel_id = ?
|
|
`
|
|
|
|
type IsDMParticipantParams struct {
|
|
UserID int64 `json:"userId"`
|
|
ChannelID int64 `json:"channelId"`
|
|
}
|
|
|
|
func (q *Queries) IsDMParticipant(ctx context.Context, arg IsDMParticipantParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, isDMParticipant, arg.UserID, arg.ChannelID)
|
|
var user_id int64
|
|
err := row.Scan(&user_id)
|
|
return user_id, err
|
|
}
|
|
|
|
const openDM = `-- name: OpenDM :exec
|
|
INSERT OR IGNORE INTO dm_open_state (user_id, channel_id) VALUES (?, ?)
|
|
`
|
|
|
|
type OpenDMParams struct {
|
|
UserID int64 `json:"userId"`
|
|
ChannelID int64 `json:"channelId"`
|
|
}
|
|
|
|
func (q *Queries) OpenDM(ctx context.Context, arg OpenDMParams) error {
|
|
_, err := q.db.ExecContext(ctx, openDM, arg.UserID, arg.ChannelID)
|
|
return err
|
|
}
|