修复客服后台聊天无实时刷新
后台 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:
co-authored by
Claude Opus 4.8
parent
9271f47553
commit
cc1c0d33de
@@ -135,6 +135,25 @@ func (h *Hub) NotifyUser(pType string, pID uint64, event *ChatEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
// NotifyAllAdmins 向所有在线管理员(客服)推送事件。
|
||||
// 客服工作台的「未分配 / 全部」视图会展示当前客服并非参与者的会话,
|
||||
// 仅靠 NotifyConversation(只推参与者)无法实时刷新,故对所有在线客服广播。
|
||||
func (h *Hub) NotifyAllAdmins(event *ChatEvent) {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
for key, clients := range h.clients {
|
||||
if key.Type != "admin" {
|
||||
continue
|
||||
}
|
||||
for ch := range clients {
|
||||
select {
|
||||
case ch <- event:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalEvent 将事件序列化为 SSE data 行。
|
||||
func MarshalEvent(event *ChatEvent) string {
|
||||
raw, _ := json.Marshal(event)
|
||||
|
||||
Reference in New Issue
Block a user