diff --git a/backend/app/services/ws_manager.py b/backend/app/services/ws_manager.py index c11782e..acc3f1b 100644 --- a/backend/app/services/ws_manager.py +++ b/backend/app/services/ws_manager.py @@ -250,6 +250,55 @@ class ConnectionManager: for employee_id in employee_ids: 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 + # ========================================================================== # 辅助方法 # ==========================================================================