修复拍一拍消息重复显示的问题,按发送者/被拍者路由到包厢,其他用户路由到公屏

This commit is contained in:
pllx
2026-04-29 09:40:40 +08:00
parent 434f2b8e0f
commit 2f9b2eed64
+16 -12
View File
@@ -126,20 +126,24 @@ function appendPatMessage(displayText, fromUserHeadface, fromUser, targetUser) {
div.innerHTML = headImg + fromHtml + "对" + toHtml + "说:<span class=\"msg-content\" style=\"color: #000000\">👋 我刚拍了拍你</span> <span class=\"msg-time\">(" + timeStr + ")</span>";
container.appendChild(div);
pruneMessageContainer(container, 600);
if (state?.autoScroll) {
container.scrollTop = container.scrollHeight;
}
// 路由规则:发送者和被拍者在包厢看到,其他用户在公屏看到
const currentUser = window.chatContext?.username || "";
const isRelatedToMe = fromUser === currentUser || targetUser === currentUser;
// 同时在包厢窗口(say2)也显示
const container2 = state?.container2;
if (container2) {
const div2 = div.cloneNode(true);
container2.appendChild(div2);
pruneMessageContainer(container2, 300);
if (isRelatedToMe) {
const container2 = state?.container2;
if (container2) {
container2.appendChild(div);
pruneMessageContainer(container2, 300);
if (state?.autoScroll) {
container2.scrollTop = container2.scrollHeight;
}
}
} else {
container.appendChild(div);
pruneMessageContainer(container, 600);
if (state?.autoScroll) {
container2.scrollTop = container2.scrollHeight;
container.scrollTop = container.scrollHeight;
}
}
}