加固房间准入与消息广播边界
This commit is contained in:
@@ -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 }),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user