Changeset 0.37.14 (#226)

Co-authored-by: gobha <jasafpro@gmail.com>
Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
2026-03-23 16:47:48 +00:00
committed by xcaliber
parent fcb998bff9
commit b7746c3004
164 changed files with 6972 additions and 3527 deletions

View File

@@ -338,9 +338,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 = ? 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 = ? ORDER BY cp.joined_at`, channelID)
if err != nil {
return nil, err
}
@@ -518,6 +522,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 = 1, purge_after = ?, updated_at = datetime('now')
WHERE id = ?
`, purgeAfter.UTC().Format("2006-01-02T15:04:05Z"), channelID)
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 <= datetime('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 {
_, err := DB.ExecContext(ctx, `
UPDATE channel_participants

View File

@@ -41,9 +41,9 @@ func (s *FolderStore) List(ctx context.Context, userID string) ([]models.Folder,
func (s *FolderStore) Create(ctx context.Context, f *models.Folder) error {
f.ID = store.NewID()
_, err := DB.ExecContext(ctx, `
INSERT INTO folders (id, user_id, name, sort_order)
VALUES (?, ?, ?, ?)
`, f.ID, f.UserID, f.Name, f.SortOrder)
INSERT INTO folders (id, user_id, name, parent_id, sort_order)
VALUES (?, ?, ?, ?, ?)
`, f.ID, f.UserID, f.Name, f.ParentID, f.SortOrder)
if err != nil {
return err
}
@@ -53,7 +53,20 @@ func (s *FolderStore) Create(ctx context.Context, f *models.Folder) error {
`, f.ID).Scan(&f.Name, &f.ParentID, &f.SortOrder, st(&f.CreatedAt), st(&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(?, ''), name),
sort_order = COALESCE(?, sort_order),
parent_id = ?
WHERE id = ? AND user_id = ?
`, name, sortOrder, *parentID, folderID, userID)
if err != nil {
return 0, err
}
return res.RowsAffected()
}
res, err := DB.ExecContext(ctx, `
UPDATE folders
SET name = COALESCE(NULLIF(?, ''), name),

View File

@@ -260,7 +260,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