feat(ws): P1-4 实现 broadcast_message_status 实时广播

This commit is contained in:
Simon
2026-06-14 21:56:18 +08:00
parent 2cd162eb17
commit 59c5df356b
+49
View File
@@ -250,6 +250,55 @@ class ConnectionManager:
for employee_id in employee_ids: for employee_id in employee_ids:
await self.send_to_employee(employee_id, data) await self.send_to_employee(employee_id, data)
# ==========================================================================
# 消息状态广播(P1-4
# ==========================================================================
async def broadcast_message_status(
self,
conv_id: str,
msg_id: str,
status: str,
participant_ids: List[str],
extra: dict = None,
) -> int:
"""向会话所有参与方广播消息状态变更。
用于撤回/已读/删除等事件的实时推送。
Args:
conv_id: 会话ID
msg_id: 消息ID
status: 新状态 (sent / delivered / read / recalled / deleted)
participant_ids: 参与方ID列表 (agent_id + employee_id)
extra: 额外数据 (可选,如 recall_by / recall_at)
Returns:
推送到客户端数量
"""
# 构建消息
payload = {
"type": "message_status",
"conv_id": conv_id,
"msg_id": msg_id,
"status": status,
**(extra or {}),
}
# 分别推送给坐席和员工
sent_count = 0
for pid in participant_ids:
# 判断是坐席还是员工
if pid in self.active_connections:
await self.send_to_agent(pid, payload)
sent_count += 1
elif pid in self.employee_connections:
await self.send_to_employee(pid, payload)
sent_count += 1
return sent_count
# ========================================================================== # ==========================================================================
# 辅助方法 # 辅助方法
# ========================================================================== # ==========================================================================