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.

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

package store

import (
	"context"

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

const getRoomParticipationForAccount = `-- name: GetRoomParticipationForAccount :one
SELECT NOT room_actor_participating(room.id,caller.id)::boolean AS has_left
FROM rooms room
JOIN actors caller ON caller.tenant_id=room.tenant_id AND caller.account_id=$2 AND caller.kind='human'
JOIN active_room_members membership ON membership.room_id=collaboration_membership_room_id(room.id) AND membership.actor_id=caller.id
WHERE room.id=$1
`

type GetRoomParticipationForAccountParams struct {
	ID        string      `json:"id"`
	AccountID pgtype.Text `json:"account_id"`
}

func (q *Queries) GetRoomParticipationForAccount(ctx context.Context, arg GetRoomParticipationForAccountParams) (pgtype.Bool, error) {
	row := q.db.QueryRow(ctx, getRoomParticipationForAccount, arg.ID, arg.AccountID)
	var has_left pgtype.Bool
	err := row.Scan(&has_left)
	return has_left, err
}

const setRoomParticipation = `-- name: SetRoomParticipation :exec
INSERT INTO room_member_states(room_id,actor_id,read_through_room_seq,left_at,left_room_seq,participation_epoch_id)
VALUES($1,$2,$3,CASE WHEN $4::boolean THEN clock_timestamp() ELSE NULL END,$3,(SELECT membership_epoch_id FROM room_members WHERE room_id=$1 AND actor_id=$2))
ON CONFLICT (room_id,actor_id) DO UPDATE
SET participation_epoch_id=excluded.participation_epoch_id,left_at=excluded.left_at,left_room_seq=excluded.left_room_seq,
    read_through_room_seq=greatest(room_member_states.read_through_room_seq,excluded.read_through_room_seq),updated_at=now()
`

type SetRoomParticipationParams struct {
	RoomID  string `json:"room_id"`
	ActorID string `json:"actor_id"`
	RoomSeq int64  `json:"room_seq"`
	HasLeft bool   `json:"has_left"`
}

func (q *Queries) SetRoomParticipation(ctx context.Context, arg SetRoomParticipationParams) error {
	_, err := q.db.Exec(ctx, setRoomParticipation,
		arg.RoomID,
		arg.ActorID,
		arg.RoomSeq,
		arg.HasLeft,
	)
	return err
}

const setThreadParticipationReadStates = `-- name: SetThreadParticipationReadStates :exec
INSERT INTO room_member_states(room_id,actor_id,read_through_room_seq,left_at,left_room_seq,participation_epoch_id)
SELECT child.id,$1,child.next_room_seq,CASE WHEN $2::boolean THEN clock_timestamp() ELSE NULL END,child.next_room_seq,membership.membership_epoch_id
FROM rooms child
JOIN room_members membership ON membership.room_id=child.parent_room_id AND membership.actor_id=$1
WHERE child.parent_room_id=$3::text
ON CONFLICT (room_id,actor_id) DO UPDATE SET left_room_seq=excluded.left_room_seq,left_at=excluded.left_at,participation_epoch_id=excluded.participation_epoch_id,read_through_room_seq=greatest(room_member_states.read_through_room_seq,excluded.read_through_room_seq)
`

type SetThreadParticipationReadStatesParams struct {
	ActorID string `json:"actor_id"`
	HasLeft bool   `json:"has_left"`
	RoomID  string `json:"room_id"`
}

func (q *Queries) SetThreadParticipationReadStates(ctx context.Context, arg SetThreadParticipationReadStatesParams) error {
	_, err := q.db.Exec(ctx, setThreadParticipationReadStates, arg.ActorID, arg.HasLeft, arg.RoomID)
	return err
}