Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

10.9 KB
Raw Blame
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: room_history_share.sql

package store

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const createRoomHistoryShare = `-- name: CreateRoomHistoryShare :one
INSERT INTO room_history_shares(
  id, room_id, creator_actor_id, creator_membership_epoch_id, token_hash,
  room_name, snapshot_room_seq, web_version
) VALUES (
  $1::text, $2::text, $3::text,
  $4::text, $5::bytea,
  $6::text, $7::bigint, $8::text
)
RETURNING created_at
`

type CreateRoomHistoryShareParams struct {
	ID                       string `json:"id"`
	RoomID                   string `json:"room_id"`
	CreatorActorID           string `json:"creator_actor_id"`
	CreatorMembershipEpochID string `json:"creator_membership_epoch_id"`
	TokenHash                []byte `json:"token_hash"`
	RoomName                 string `json:"room_name"`
	SnapshotRoomSeq          int64  `json:"snapshot_room_seq"`
	WebVersion               string `json:"web_version"`
}

func (q *Queries) CreateRoomHistoryShare(ctx context.Context, arg CreateRoomHistoryShareParams) (pgtype.Timestamptz, error) {
	row := q.db.QueryRow(ctx, createRoomHistoryShare,
		arg.ID,
		arg.RoomID,
		arg.CreatorActorID,
		arg.CreatorMembershipEpochID,
		arg.TokenHash,
		arg.RoomName,
		arg.SnapshotRoomSeq,
		arg.WebVersion,
	)
	var created_at pgtype.Timestamptz
	err := row.Scan(&created_at)
	return created_at, err
}

const createRoomHistoryShareAsset = `-- name: CreateRoomHistoryShareAsset :exec
INSERT INTO room_history_share_assets(share_id, id, media_type, content)
VALUES ($1::text, $2::text, $3::text, $4::bytea)
`

type CreateRoomHistoryShareAssetParams struct {
	ShareID   string `json:"share_id"`
	ID        string `json:"id"`
	MediaType string `json:"media_type"`
	Content   []byte `json:"content"`
}

func (q *Queries) CreateRoomHistoryShareAsset(ctx context.Context, arg CreateRoomHistoryShareAssetParams) error {
	_, err := q.db.Exec(ctx, createRoomHistoryShareAsset,
		arg.ShareID,
		arg.ID,
		arg.MediaType,
		arg.Content,
	)
	return err
}

const createRoomHistoryShareMessage = `-- name: CreateRoomHistoryShareMessage :exec
INSERT INTO room_history_share_messages(share_id, position, message_id, presentation)
VALUES ($1::text, $2::bigint, $3::text, $4::jsonb)
`

type CreateRoomHistoryShareMessageParams struct {
	ShareID      string `json:"share_id"`
	Position     int64  `json:"position"`
	MessageID    string `json:"message_id"`
	Presentation []byte `json:"presentation"`
}

func (q *Queries) CreateRoomHistoryShareMessage(ctx context.Context, arg CreateRoomHistoryShareMessageParams) error {
	_, err := q.db.Exec(ctx, createRoomHistoryShareMessage,
		arg.ShareID,
		arg.Position,
		arg.MessageID,
		arg.Presentation,
	)
	return err
}

const getAuthorizedRoomHistoryShare = `-- name: GetAuthorizedRoomHistoryShare :one
SELECT share.id, share.room_name, share.created_at, share.message_count, share.snapshot_room_seq
FROM room_history_shares share
JOIN rooms room ON room.id=share.room_id
JOIN active_room_members member
  ON member.room_id=share.room_id AND member.actor_id=share.creator_actor_id
 AND member.membership_epoch_id=share.creator_membership_epoch_id
WHERE share.token_hash=$1::bytea AND share.revoked_at IS NULL
  AND room.deleted_at IS NULL AND room.deletion_started_at IS NULL
`

type GetAuthorizedRoomHistoryShareRow struct {
	ID              string             `json:"id"`
	RoomName        string             `json:"room_name"`
	CreatedAt       pgtype.Timestamptz `json:"created_at"`
	MessageCount    int32              `json:"message_count"`
	SnapshotRoomSeq int64              `json:"snapshot_room_seq"`
}

func (q *Queries) GetAuthorizedRoomHistoryShare(ctx context.Context, tokenHash []byte) (GetAuthorizedRoomHistoryShareRow, error) {
	row := q.db.QueryRow(ctx, getAuthorizedRoomHistoryShare, tokenHash)
	var i GetAuthorizedRoomHistoryShareRow
	err := row.Scan(
		&i.ID,
		&i.RoomName,
		&i.CreatedAt,
		&i.MessageCount,
		&i.SnapshotRoomSeq,
	)
	return i, err
}

const getDocumentVersionContentObjectID = `-- name: GetDocumentVersionContentObjectID :one
SELECT content_object_id FROM document_versions WHERE id=$1::text
`

func (q *Queries) GetDocumentVersionContentObjectID(ctx context.Context, id string) (string, error) {
	row := q.db.QueryRow(ctx, getDocumentVersionContentObjectID, id)
	var content_object_id string
	err := row.Scan(&content_object_id)
	return content_object_id, err
}

const getHumanActorAvatarImage = `-- name: GetHumanActorAvatarImage :one
SELECT account.profile_avatar_image
FROM actors actor
JOIN accounts account ON account.id=actor.account_id
WHERE actor.tenant_id=$1::text AND actor.id=$2::text
`

type GetHumanActorAvatarImageParams struct {
	TenantID string `json:"tenant_id"`
	ActorID  string `json:"actor_id"`
}

func (q *Queries) GetHumanActorAvatarImage(ctx context.Context, arg GetHumanActorAvatarImageParams) (string, error) {
	row := q.db.QueryRow(ctx, getHumanActorAvatarImage, arg.TenantID, arg.ActorID)
	var profile_avatar_image string
	err := row.Scan(&profile_avatar_image)
	return profile_avatar_image, err
}

const getHumanRoomMembershipForShare = `-- name: GetHumanRoomMembershipForShare :one
SELECT actor.id AS actor_id, member.membership_epoch_id, member.role
FROM active_room_members member
JOIN actors actor ON actor.id=member.actor_id
WHERE member.room_id=$1::text
  AND actor.account_id=$2::text
  AND actor.kind='human'
`

type GetHumanRoomMembershipForShareParams struct {
	RoomID    string `json:"room_id"`
	AccountID string `json:"account_id"`
}

type GetHumanRoomMembershipForShareRow struct {
	ActorID           string `json:"actor_id"`
	MembershipEpochID string `json:"membership_epoch_id"`
	Role              string `json:"role"`
}

func (q *Queries) GetHumanRoomMembershipForShare(ctx context.Context, arg GetHumanRoomMembershipForShareParams) (GetHumanRoomMembershipForShareRow, error) {
	row := q.db.QueryRow(ctx, getHumanRoomMembershipForShare, arg.RoomID, arg.AccountID)
	var i GetHumanRoomMembershipForShareRow
	err := row.Scan(&i.ActorID, &i.MembershipEpochID, &i.Role)
	return i, err
}

const getRoomHistoryShareAsset = `-- name: GetRoomHistoryShareAsset :one
SELECT media_type, content FROM room_history_share_assets
WHERE share_id=$1::text AND id=$2::text
`

type GetRoomHistoryShareAssetParams struct {
	ShareID string `json:"share_id"`
	ID      string `json:"id"`
}

type GetRoomHistoryShareAssetRow struct {
	MediaType string `json:"media_type"`
	Content   []byte `json:"content"`
}

func (q *Queries) GetRoomHistoryShareAsset(ctx context.Context, arg GetRoomHistoryShareAssetParams) (GetRoomHistoryShareAssetRow, error) {
	row := q.db.QueryRow(ctx, getRoomHistoryShareAsset, arg.ShareID, arg.ID)
	var i GetRoomHistoryShareAssetRow
	err := row.Scan(&i.MediaType, &i.Content)
	return i, err
}

const listRoomHistoryShareMessages = `-- name: ListRoomHistoryShareMessages :many
SELECT presentation FROM room_history_share_messages
WHERE share_id=$1::text AND position>$2::bigint
ORDER BY position
LIMIT 50
`

type ListRoomHistoryShareMessagesParams struct {
	ShareID       string `json:"share_id"`
	AfterPosition int64  `json:"after_position"`
}

func (q *Queries) ListRoomHistoryShareMessages(ctx context.Context, arg ListRoomHistoryShareMessagesParams) ([][]byte, error) {
	rows, err := q.db.Query(ctx, listRoomHistoryShareMessages, arg.ShareID, arg.AfterPosition)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := [][]byte{}
	for rows.Next() {
		var presentation []byte
		if err := rows.Scan(&presentation); err != nil {
			return nil, err
		}
		items = append(items, presentation)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listRoomHistoryShares = `-- name: ListRoomHistoryShares :many
SELECT id, room_name, created_at, message_count, snapshot_room_seq,
       (revoked_at IS NOT NULL)::boolean AS revoked
FROM room_history_shares
WHERE room_id=$1::text
ORDER BY created_at DESC, id DESC
`

type ListRoomHistorySharesRow struct {
	ID              string             `json:"id"`
	RoomName        string             `json:"room_name"`
	CreatedAt       pgtype.Timestamptz `json:"created_at"`
	MessageCount    int32              `json:"message_count"`
	SnapshotRoomSeq int64              `json:"snapshot_room_seq"`
	Revoked         bool               `json:"revoked"`
}

func (q *Queries) ListRoomHistoryShares(ctx context.Context, roomID string) ([]ListRoomHistorySharesRow, error) {
	rows, err := q.db.Query(ctx, listRoomHistoryShares, roomID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListRoomHistorySharesRow{}
	for rows.Next() {
		var i ListRoomHistorySharesRow
		if err := rows.Scan(
			&i.ID,
			&i.RoomName,
			&i.CreatedAt,
			&i.MessageCount,
			&i.SnapshotRoomSeq,
			&i.Revoked,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const revokeRoomHistoryShare = `-- name: RevokeRoomHistoryShare :execrows
UPDATE room_history_shares SET revoked_at=coalesce(revoked_at, now())
WHERE room_id=$1::text AND id=$2::text
`

type RevokeRoomHistoryShareParams struct {
	RoomID string `json:"room_id"`
	ID     string `json:"id"`
}

func (q *Queries) RevokeRoomHistoryShare(ctx context.Context, arg RevokeRoomHistoryShareParams) (int64, error) {
	result, err := q.db.Exec(ctx, revokeRoomHistoryShare, arg.RoomID, arg.ID)
	if err != nil {
		return 0, err
	}
	return result.RowsAffected(), nil
}

const rotateRoomHistoryShareToken = `-- name: RotateRoomHistoryShareToken :one
UPDATE room_history_shares
SET token_hash=$1::bytea
WHERE id=$2::text AND room_id=$3::text AND revoked_at IS NULL
RETURNING id, room_name, created_at, message_count, snapshot_room_seq
`

type RotateRoomHistoryShareTokenParams struct {
	TokenHash []byte `json:"token_hash"`
	ID        string `json:"id"`
	RoomID    string `json:"room_id"`
}

type RotateRoomHistoryShareTokenRow struct {
	ID              string             `json:"id"`
	RoomName        string             `json:"room_name"`
	CreatedAt       pgtype.Timestamptz `json:"created_at"`
	MessageCount    int32              `json:"message_count"`
	SnapshotRoomSeq int64              `json:"snapshot_room_seq"`
}

func (q *Queries) RotateRoomHistoryShareToken(ctx context.Context, arg RotateRoomHistoryShareTokenParams) (RotateRoomHistoryShareTokenRow, error) {
	row := q.db.QueryRow(ctx, rotateRoomHistoryShareToken, arg.TokenHash, arg.ID, arg.RoomID)
	var i RotateRoomHistoryShareTokenRow
	err := row.Scan(
		&i.ID,
		&i.RoomName,
		&i.CreatedAt,
		&i.MessageCount,
		&i.SnapshotRoomSeq,
	)
	return i, err
}

const setRoomHistoryShareMessageCount = `-- name: SetRoomHistoryShareMessageCount :exec
UPDATE room_history_shares SET message_count=$1::int
WHERE id=$2::text
`

type SetRoomHistoryShareMessageCountParams struct {
	MessageCount int32  `json:"message_count"`
	ID           string `json:"id"`
}

func (q *Queries) SetRoomHistoryShareMessageCount(ctx context.Context, arg SetRoomHistoryShareMessageCountParams) error {
	_, err := q.db.Exec(ctx, setRoomHistoryShareMessageCount, arg.MessageCount, arg.ID)
	return err
}