- ws_hub.go 182(hub核心/常量/wsEvent/newHub/broadcast) + ws_hub_conn.go 165(连接层handleWS/read·writePump) + ws_hub_turn.go 168(relay/streamChat/runTurn/interrupt/broadcastStream) + ws_hub_origin.go 73(Origin校验) + ws_hub_message_event.go 30(message_edited/deleted广播) - 代码行多重集 identical + 顶层声明diff空; 每文件≤500/函数≤80(最大handleWS 28/streamChat 25) - gateway测试绿 + build/vet + win/darwin交叉编译绿
31 lines
1.6 KiB
Go
31 lines
1.6 KiB
Go
package gateway
|
|
|
|
// wsMessageEdited / wsMessageDeleted are the downstream event types of the D3
|
|
// history writes: a message's content was edited, or a message was removed. Both
|
|
// reuse the wsEvent envelope and the same all-connections fan-out as
|
|
// `message_persisted` — the hub has no per-session subscription, so the frame
|
|
// carries SessionID and a client filters it by its active session, exactly as it
|
|
// does for message_persisted.
|
|
const (
|
|
wsMessageEdited = "message_edited"
|
|
wsMessageDeleted = "message_deleted"
|
|
)
|
|
|
|
// broadcastMessageEdited fans a content edit out to every client as a
|
|
// `message_edited` frame whose data is the updated message DTO. The frame is a
|
|
// render-only sync: the edited content's single source of truth stays the history
|
|
// store, so a client that missed the frame converges again on its next read. The
|
|
// caller strips Thinking to match the message_persisted/replay contract.
|
|
func (h *hub) broadcastMessageEdited(msg historyMessage) {
|
|
h.broadcast(wsEvent{Type: wsMessageEdited, SessionID: msg.SessionID, Data: msg})
|
|
}
|
|
|
|
// broadcastMessageDeleted fans a removal out to every client as a
|
|
// `message_deleted` frame carrying the removed id (plus the owning sessionId for
|
|
// client-side session filtering), so every browser of the account drops the row
|
|
// without a refresh. sessionID may be empty when the store could not report it;
|
|
// clients then fall back to the globally unique id.
|
|
func (h *hub) broadcastMessageDeleted(sessionID, id string) {
|
|
h.broadcast(wsEvent{Type: wsMessageDeleted, SessionID: sessionID, Data: map[string]any{"id": id}})
|
|
}
|