package history import ( "context" "fmt" ) // SetPinned pins or unpins a persistent session. Pinning is display/order metadata // only (like the title): both the fixed main session and sub sessions may be pinned, // and identity/permissions never derive from it. An unknown id returns // ErrSessionNotFound. func (s *Store) SetPinned(ctx context.Context, sessionID string, pinned bool) error { res, err := s.db.ExecContext(ctx, `UPDATE chat_sessions SET pinned = ? WHERE id = ?`, pinnedValue(pinned), sessionID) if err != nil { return fmt.Errorf("history: set pinned %s: %w", sessionID, err) } n, err := res.RowsAffected() if err != nil { return fmt.Errorf("history: set pinned %s rows: %w", sessionID, err) } if n == 0 { return fmt.Errorf("history: set pinned %s: %w", sessionID, ErrSessionNotFound) } return nil } // pinnedValue maps the boolean to SQLite's 0/1 integer representation. func pinnedValue(pinned bool) int { if pinned { return 1 } return 0 }