docs(gateway): WS 帧门相关 11 个文件的注释改中文(只改注释,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」。本次先把本会话动过的文件就地翻; 不做全仓一次性翻译,存量按包分批排期(见 工作小结.md 待办)。 范围:ws_frame_scope.go / ws_frame_scope_test.go / broadcast.go / ws_hub_turn.go / ws_hub_message_event.go / session_read.go / server.go / ws_hub_stream_scope_test.go / history_write_broadcast_test.go / mood_test.go / extra_test.go 含中文的整行注释 18 → 382。 校验(判据 = "只改注释、零代码字节改动"): - `git diff -U0 | 排除 +++/--- | 排除注释行/空行/行尾注释` → 为空 - 独立实现:两侧剥掉注释后逐行比对代码文本 → 11/11 文件全等,不一致数 0 - 行尾注释 7 行逐条列出,代码列与原文逐字节相同(gofmt 未要求重排) - gofmt -l 干净;全树 go build/vet 绿;go test ./... = 58 包 ok / 0 FAIL; linux/amd64 + darwin/arm64 交叉编译绿 语义未删减:部分折行英文长句合并为更少行,故整行注释数 438 → 399。
This commit is contained in:
1 parent
770a83c3fb
commit
fe1ff33115
11 files changed
+392
-431
No files matched your search
@@ -11,39 +11,36 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
|
||||
)
|
||||
|
||||
// This file owns the D4 read-cursor surface (Android collaboration B3): the
|
||||
// POST /api/v1/sessions/{id}/read endpoint that advances a session's read cursor,
|
||||
// plus the `session_read` realtime frame it broadcasts so the account's other
|
||||
// browsers clear the unread badge without a re-read. The cursor itself lives in
|
||||
// chat_sessions.read_at (internal/runtime/history); GET /sessions derives the
|
||||
// unreadCount from it (history.go). The cursor is session-scoped and single-owner:
|
||||
// one account, one cursor per session — reading on any one end marks the session
|
||||
// read for every end.
|
||||
// 本文件归属 D4 已读游标面(Android 协作 B3):推进会话已读游标的
|
||||
// POST /api/v1/sessions/{id}/read 端点,以及它为清除账号其他浏览器
|
||||
// 未读徽标(无需重读)而广播的 `session_read` 实时帧。游标本身存于
|
||||
// chat_sessions.read_at(internal/runtime/history);GET /sessions 由它
|
||||
// 推导 unreadCount(history.go)。游标是会话级、单所有者的:
|
||||
// 一个账号每个会话一个游标 —— 在任意一端阅读即为所有端标记该
|
||||
// 会话已读。
|
||||
|
||||
// wsSessionRead is the WS event type for a read-cursor advance.
|
||||
// wsSessionRead 是已读游标推进的 WS 事件类型。
|
||||
const wsSessionRead = "session_read"
|
||||
|
||||
// sessionReadRequest is the POST /api/v1/sessions/{id}/read body. Before is a
|
||||
// pointer so an absent field (an empty body) is distinguishable from an explicit
|
||||
// value: absent means "now" — the client marks everything it has seen read.
|
||||
// sessionReadRequest 是 POST /api/v1/sessions/{id}/read 的请求体。
|
||||
// Before 是指针,以便把字段缺失(空请求体)与显式取值区分开:
|
||||
// 缺失表示「现在」—— 客户端把它已看到的一切都标记为已读。
|
||||
type sessionReadRequest struct {
|
||||
Before *int64 `json:"before"`
|
||||
}
|
||||
|
||||
// handleMarkSessionRead advances a session's read cursor and answers
|
||||
// {data:{sessionId, readAt}} with the resulting cursor in Unix milliseconds.
|
||||
// It is owner/admin-gated like the other history writes (writeAuth).
|
||||
// handleMarkSessionRead 推进会话的已读游标,并以 Unix 毫秒返回结果
|
||||
// 游标 {data:{sessionId, readAt}}。与其他历史写入一样走 owner/admin
|
||||
// 门(writeAuth)。
|
||||
//
|
||||
// body {before?} is an optional millisecond timestamp bounding what is marked
|
||||
// read — messages with created_at <= readAt become read. Absent (or an empty body)
|
||||
// means now. A present non-positive or non-numeric before answers 400: the cursor
|
||||
// is a real millisecond timestamp, and "unread by a negative cursor" is not a
|
||||
// meaningful client request. An unknown session id answers 404; a missing
|
||||
// HistoryStore answers 501.
|
||||
// 请求体 {before?} 是可选毫秒时间戳,界定标记已读的范围 ——
|
||||
// created_at <= readAt 的消息变为已读。缺失(或空请求体)表示现在。
|
||||
// 已给出但非正数或非数值的 before 返回 400:游标是真实的毫秒
|
||||
// 时间戳,「负数游标造成的未读」不是有意义的客户端请求。未知
|
||||
// 会话 id 返回 404;HistoryStore 缺失返回 501。
|
||||
//
|
||||
// On success the new cursor is broadcast as a `session_read` frame so the account's
|
||||
// other browsers clear the badge too (reading on one end = read everywhere). A
|
||||
// failure path broadcasts nothing.
|
||||
// 成功时新游标作为 `session_read` 帧广播,使该账号其他浏览器也清除
|
||||
// 徽标(一端阅读 = 处处已读)。失败路径不广播任何东西。
|
||||
func (s *Server) handleMarkSessionRead(w http.ResponseWriter, r *http.Request) {
|
||||
if s.history == nil {
|
||||
writeError(w, &apperr.AppError{Code: "not_implemented", Message: "会话历史服务未配置(未注入 HistoryStore)", HTTPCode: http.StatusNotImplemented})
|
||||
@@ -81,15 +78,13 @@ func (s *Server) handleMarkSessionRead(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"sessionId": id, "readAt": readAt})
|
||||
}
|
||||
|
||||
// broadcastSessionRead fans a read-cursor advance out to every client as a
|
||||
// `session_read` frame carrying the session's new cursor, so the same account's
|
||||
// other ends clear the session's unread badge without a re-read. It is one of the
|
||||
// design/11 §7.1 「状态机信号」 (it reports a cursor, never a message body), so the
|
||||
// frame gate keeps it on the all-connections path. Like the other history frames it
|
||||
// relies on the hub having no per-session
|
||||
// subscription), and the client filters it by sessionId; the cursor's single source
|
||||
// of truth stays chat_sessions.read_at, so a client that missed the frame converges
|
||||
// on its next GET /sessions.
|
||||
// broadcastSessionRead 把一次已读游标推进作为 `session_read` 帧扇出到
|
||||
// 每个客户端,携带会话的新游标,使同一账号的其他端无需重读即可
|
||||
// 清除该会话的未读徽标。它属于 design/11 §7.1 的「状态机信号」
|
||||
// (只报告游标,绝不报告消息正文),因此帧门让它留在全连接路径上。
|
||||
// 与其他历史帧一样,它依赖 hub 没有按会话订阅这一点,由客户端按
|
||||
// sessionId 过滤;游标的唯一事实来源仍是 chat_sessions.read_at,
|
||||
// 因此错过该帧的客户端会在下次 GET /sessions 时重新收敛。
|
||||
func (h *hub) broadcastSessionRead(sessionID string, readAt int64) {
|
||||
h.broadcast(wsEvent{
|
||||
Type: wsSessionRead,
|
||||
|
||||
Reference in new issue
Block a user