Changeset 0.37.14 (#226)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
@@ -339,9 +339,13 @@ func (s *ChannelStore) AddParticipant(ctx context.Context, p *models.ChannelPart
|
||||
|
||||
func (s *ChannelStore) ListParticipants(ctx context.Context, channelID string) ([]models.ChannelParticipant, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT id, channel_id, participant_type, participant_id, role,
|
||||
display_name, avatar_url, joined_at
|
||||
FROM channel_participants WHERE channel_id = $1 ORDER BY joined_at`, channelID)
|
||||
SELECT cp.id, cp.channel_id, cp.participant_type, cp.participant_id, cp.role,
|
||||
COALESCE(NULLIF(cp.display_name,''), NULLIF(u.display_name,''), u.username) AS display_name,
|
||||
COALESCE(NULLIF(cp.avatar_url,''), u.avatar_url) AS avatar_url,
|
||||
cp.joined_at
|
||||
FROM channel_participants cp
|
||||
LEFT JOIN users u ON cp.participant_type = 'user' AND cp.participant_id = u.id
|
||||
WHERE cp.channel_id = $1 ORDER BY cp.joined_at`, channelID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -515,6 +519,32 @@ func (s *ChannelStore) DeleteByOwner(ctx context.Context, channelID, userID stri
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
func (s *ChannelStore) ArchiveForRetention(ctx context.Context, channelID string, purgeAfter time.Time) error {
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
UPDATE channels SET is_archived = true, purge_after = $2, updated_at = NOW()
|
||||
WHERE id = $1
|
||||
`, channelID, purgeAfter)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ChannelStore) ListPurgeable(ctx context.Context) ([]string, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT id FROM channels WHERE purge_after IS NOT NULL AND purge_after <= NOW()
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var ids []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if rows.Scan(&id) == nil {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
return ids, rows.Err()
|
||||
}
|
||||
|
||||
func (s *ChannelStore) MarkRead(ctx context.Context, channelID, userID string) error {
|
||||
// Update last_read_at
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
|
||||
@@ -39,14 +39,27 @@ func (s *FolderStore) List(ctx context.Context, userID string) ([]models.Folder,
|
||||
|
||||
func (s *FolderStore) Create(ctx context.Context, f *models.Folder) error {
|
||||
return DB.QueryRowContext(ctx, `
|
||||
INSERT INTO folders (user_id, name, sort_order)
|
||||
VALUES ($1, $2, $3)
|
||||
INSERT INTO folders (user_id, name, parent_id, sort_order)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, name, parent_id, sort_order, created_at, updated_at
|
||||
`, f.UserID, f.Name, f.SortOrder).Scan(
|
||||
`, f.UserID, f.Name, f.ParentID, f.SortOrder).Scan(
|
||||
&f.ID, &f.Name, &f.ParentID, &f.SortOrder, &f.CreatedAt, &f.UpdatedAt)
|
||||
}
|
||||
|
||||
func (s *FolderStore) Update(ctx context.Context, folderID, userID string, name string, sortOrder *int) (int64, error) {
|
||||
func (s *FolderStore) Update(ctx context.Context, folderID, userID string, name string, sortOrder *int, parentID **string) (int64, error) {
|
||||
if parentID != nil {
|
||||
res, err := DB.ExecContext(ctx, `
|
||||
UPDATE folders
|
||||
SET name = COALESCE(NULLIF($3, ''), name),
|
||||
sort_order = COALESCE($4, sort_order),
|
||||
parent_id = $5
|
||||
WHERE id = $1 AND user_id = $2
|
||||
`, folderID, userID, name, sortOrder, *parentID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
res, err := DB.ExecContext(ctx, `
|
||||
UPDATE folders
|
||||
SET name = COALESCE(NULLIF($3, ''), name),
|
||||
|
||||
@@ -256,7 +256,7 @@ func (s *MessageStore) ListWithSenderInfo(ctx context.Context, channelID string,
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT m.id, m.channel_id, m.role, m.content, m.model, m.tokens_used, m.parent_id,
|
||||
m.sibling_index, m.participant_type, m.participant_id,
|
||||
CASE WHEN m.participant_type = 'user' THEN COALESCE(u.display_name, u.username)
|
||||
CASE WHEN m.participant_type = 'user' THEN COALESCE(NULLIF(u.display_name, ''), u.username)
|
||||
WHEN m.participant_type = 'persona' THEN p.name
|
||||
ELSE NULL END AS sender_name,
|
||||
CASE WHEN m.participant_type = 'user' THEN u.avatar_url
|
||||
|
||||
Reference in New Issue
Block a user