- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩 4 条行尾注释的翻译,代码前缀全等) - 交叉引用(design/16 §4.6、D4/B3、0010 迁移文件名)逐字保留 - 保留未译技术词:DDL/rowid/LIKE/LEFT JOIN/DTO/rune/WS/actor 及全部标识符与表名 - 顺带副作用:store.go、session_persona_test.go 由注释文字改变而变得 gofmt 干净(未运行 gofmt -w)
33 lines
952 B
Go
33 lines
952 B
Go
package history
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// SetPinned 置顶或取消置顶一个持久化会话。置顶只是展示/排序元数据(与标题
|
|
// 一样):固定主会话与子会话都可置顶,身份/权限绝不由它推导。未知 id 返回
|
|
// 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 把布尔值映射为 SQLite 的 0/1 整数表示。
|
|
func pinnedValue(pinned bool) int {
|
|
if pinned {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|