加固房间准入与消息广播边界

This commit is contained in:
2026-04-19 14:42:52 +08:00
parent 5ce83a769d
commit ba6406ed68
6 changed files with 304 additions and 14 deletions
+13
View File
@@ -9,6 +9,8 @@ export function initChat(roomId) {
return;
}
const userId = window.chatContext?.userId;
// 监听全局系统事件(如 AI 机器人开关)
window.Echo.channel('chat.system')
.listen('ChatBotToggled', (e) => {
@@ -147,6 +149,17 @@ export function initChat(roomId) {
new CustomEvent("chat:horse.settled", { detail: e }),
);
});
// 监听当前用户私有消息,确保悄悄话与定向系统通知不会泄漏给整个房间。
if (userId) {
window.Echo.private(`user.${userId}`)
.listen("MessageSent", (e) => {
console.log("收到私有聊天消息:", e.message);
window.dispatchEvent(
new CustomEvent("chat:message", { detail: e.message }),
);
});
}
}
/**