feat(channels): 适配器日志接 WS 实时推送(落库即秒推, channel_persisted)
后端: persistIsolated 由 _ = full(不广播)改为 notifyPersisted(full); BroadcastPersisted 按
sessionId 分流——main/web:<uuid> → message_persisted(Web聊天同步), 隔离 sess-xxx → channel_persisted
(适配器日志专用, 永不写主会话 web, 红线). payload data:{message:historyMessage}(strip thinking).
前端: ws.ts 新增 channel_persisted case→parseAdminChannelMessage→pushChannelEvent; wsParse.ts 纯函数;
useAppStore 新增 channelEvents(最新在前,按id去重,cap200,不持久化); channelLogList 订阅过滤
(单adapter按adapterId/总览取adapterId非空)merge进列表(仅追加、id去重、不整页重载),保留拉历史+10s兜底.
Docs/api-client.md §3.4 补 channel_persisted 契约.
验收: 后端 build/vet/test 全绿+windows/darwin交叉编译绿; 前端 npm run build 99模块绿.
注: 偏离=web:<uuid> 归 message_persisted(保Web副会话同步), 隔离永不带web前缀红线仍守.
This commit is contained in:
1 parent
9e7b4ebaac
commit
3386679d45
10 files changed
+180
-23
No files matched your search
@@ -36,7 +36,8 @@ func (b *Bridge) SetOnRejected(fn func(adapter.UnifiedMessage, string)) {
|
||||
}
|
||||
|
||||
// notifyPersisted hands a just-persisted message to the transport hook when one is
|
||||
// wired, so the gateway can broadcast `message_persisted` for cross-end sync.
|
||||
// wired, so the gateway can broadcast a `message_persisted` (web chat) or
|
||||
// `channel_persisted` (IM adapter log) event for cross-end realtime sync.
|
||||
func (b *Bridge) notifyPersisted(msg history.Message) {
|
||||
b.mu.RLock()
|
||||
fn := b.onPersisted
|
||||
@@ -73,9 +74,11 @@ func (b *Bridge) persistToMain(ctx context.Context, role, content, platform, dev
|
||||
// session (NOT the main web session) and carries the channel platform, the client
|
||||
// deviceID, the sender's display name and the account adapter registration name, so
|
||||
// the IM adapter log page can render the non-owner message stream per adapter config.
|
||||
// It is deliberately NOT broadcast to the Web main session (only owner-private
|
||||
// messages mirror to the Web). It is a no-op when no history store is wired, so the
|
||||
// bridge runs unchanged without storage.
|
||||
// The message is still NOT mirrored into the Web main session (only owner-private
|
||||
// messages mirror to the Web); it is merely handed to the transport hook so the
|
||||
// gateway broadcasts a `channel_persisted` event and the IM adapter log page appends
|
||||
// it without a refresh. It is a no-op when no history store is wired, so the bridge
|
||||
// runs unchanged without storage.
|
||||
func (b *Bridge) persistIsolated(ctx context.Context, role, content, deviceID string, sess session.Session, platform, senderName, adapterID string) {
|
||||
if b.history == nil {
|
||||
return
|
||||
@@ -89,6 +92,10 @@ func (b *Bridge) persistIsolated(ctx context.Context, role, content, deviceID st
|
||||
"session", sess.SessionID, "platform", platform, "sender_name", senderName, "adapter", adapterID)
|
||||
return
|
||||
}
|
||||
// No broadcast: third-party messages must not reach the Web main session (design/16 §4.6 §3).
|
||||
_ = full
|
||||
// Broadcast the isolated write as a `channel_persisted` event so the IM adapter
|
||||
// log page appends it in realtime. The gateway splits the event type by session:
|
||||
// this is NOT the main web session, so the web chat has no handler for it and the
|
||||
// message itself still lands only in the isolated sess-xxx session (never the
|
||||
// main/`web` session, design/16 §4.6 §3).
|
||||
b.notifyPersisted(full)
|
||||
}
|
||||
Reference in new issue
Block a user