Changeset 0.28.0.4 (#176)

This commit is contained in:
2026-03-12 12:12:17 +00:00
parent f5171d3bd3
commit 52bd36ba48
16 changed files with 520 additions and 292 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"encoding/json"
"fmt"
"strings"
"time"
@@ -419,3 +420,55 @@ func (s *ChannelStore) DeleteModelByPersona(ctx context.Context, channelID, pers
channelID, personaID)
return err
}
// ── Admin: Archived Channel Management ──────
func (s *ChannelStore) ListArchived(ctx context.Context, opts store.ListOptions) ([]store.ArchivedChannel, int, error) {
// Count
var total int
DB.QueryRowContext(ctx,
`SELECT COUNT(*) FROM channels WHERE is_archived = 1`).Scan(&total)
rows, err := DB.QueryContext(ctx, `
SELECT c.id, c.title, c.type, COALESCE(u.username, '') AS owner_name,
c.updated_at,
(SELECT COUNT(*) FROM messages WHERE channel_id = c.id) AS message_count
FROM channels c
LEFT JOIN users u ON u.id = c.user_id
WHERE c.is_archived = 1
ORDER BY c.updated_at DESC
LIMIT ? OFFSET ?`, opts.Limit, opts.Offset)
if err != nil {
return nil, 0, err
}
defer rows.Close()
var channels []store.ArchivedChannel
for rows.Next() {
var ch store.ArchivedChannel
if rows.Scan(&ch.ID, &ch.Title, &ch.Type, &ch.OwnerName, &ch.UpdatedAt, &ch.MessageCount) == nil {
channels = append(channels, ch)
}
}
if channels == nil {
channels = []store.ArchivedChannel{}
}
return channels, total, rows.Err()
}
func (s *ChannelStore) Purge(ctx context.Context, id string) error {
// Verify the channel is actually archived
var isArchived int
err := DB.QueryRowContext(ctx,
`SELECT is_archived FROM channels WHERE id = ?`, id).Scan(&isArchived)
if err != nil {
return fmt.Errorf("channel not found")
}
if isArchived == 0 {
return fmt.Errorf("channel must be archived before purging")
}
// Hard delete (CASCADE removes messages, participants, models)
_, err = DB.ExecContext(ctx, `DELETE FROM channels WHERE id = ?`, id)
return err
}