修复客服后台聊天无实时刷新

后台 token 仅存 httpOnly cookie,localStorage 无 access token,
useChatSSE 在空 token 时提前 return,导致后台 SSE 从未建立连接,
只有手动刷新才出消息。

- 前端:后台 SSE 不再因空 token 返回,去掉 query token,
  改用 withCredentials 依赖 cookie 鉴权
- 后端:新增 Hub.NotifyAllAdmins,新消息与新会话广播给所有在线客服,
  使「未分配 / 全部」视图实时刷新(参与者客服重复收到由前端按 id 去重)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
yml2213
2026-06-16 19:57:58 +08:00
co-authored by Claude Opus 4.8
parent 9271f47553
commit cc1c0d33de
4 changed files with 35 additions and 7 deletions
+6 -2
View File
@@ -136,7 +136,7 @@ func (r *Repository) SendMessage(ctx context.Context, principal Principal, conve
// 推送新消息事件给会话中的在线参与者
if r.hub != nil {
msg := items[0]
r.hub.NotifyConversation(conversationID, &chathub.ChatEvent{
event := &chathub.ChatEvent{
Type: "new_message",
ConversationID: conversationID,
Message: &chathub.MessageData{
@@ -151,7 +151,11 @@ func (r *Repository) SendMessage(ctx context.Context, principal Principal, conve
AttachmentURLS: msg.AttachmentURLS,
CreatedAt: msg.CreatedAt.Format(time.RFC3339),
},
})
}
r.hub.NotifyConversation(conversationID, event)
// 同时广播给所有在线客服,使「未分配 / 全部」视图实时刷新;
// 参与者客服会重复收到,由前端按消息 id 去重。
r.hub.NotifyAllAdmins(event)
}
return &items[0], nil
}