迁移聊天室本地清屏入口
This commit is contained in:
@@ -216,6 +216,7 @@ export {
|
|||||||
bindSoundMuteControl,
|
bindSoundMuteControl,
|
||||||
closeDailyStatusEditor,
|
closeDailyStatusEditor,
|
||||||
closeFeatureMenu,
|
closeFeatureMenu,
|
||||||
|
handleFeatureLocalClear,
|
||||||
isSoundMuted,
|
isSoundMuted,
|
||||||
loadBlockedSystemSenders,
|
loadBlockedSystemSenders,
|
||||||
normalizeChatPreferences,
|
normalizeChatPreferences,
|
||||||
@@ -248,7 +249,7 @@ export {
|
|||||||
updateRedPacketClaimsUI,
|
updateRedPacketClaimsUI,
|
||||||
} from "./chat-room/red-packet-panel.js";
|
} from "./chat-room/red-packet-panel.js";
|
||||||
export { createMessageQueue } from "./chat-room/message-queue.js";
|
export { createMessageQueue } from "./chat-room/message-queue.js";
|
||||||
export { isExpiredChatImageMessage } from "./chat-room/message-utils.js";
|
export { isExpiredChatImageMessage, localClearScreen } from "./chat-room/message-utils.js";
|
||||||
|
|
||||||
import { escapeHtml, escapeHtmlWithLineBreaks, normalizeSafeChatUrl } from "./chat-room/html.js";
|
import { escapeHtml, escapeHtmlWithLineBreaks, normalizeSafeChatUrl } from "./chat-room/html.js";
|
||||||
import { bindAppointmentAnnouncementControls, showAppointmentBanner } from "./chat-room/appointment-announcement.js";
|
import { bindAppointmentAnnouncementControls, showAppointmentBanner } from "./chat-room/appointment-announcement.js";
|
||||||
@@ -408,6 +409,7 @@ import {
|
|||||||
bindSoundMuteControl,
|
bindSoundMuteControl,
|
||||||
closeDailyStatusEditor,
|
closeDailyStatusEditor,
|
||||||
closeFeatureMenu,
|
closeFeatureMenu,
|
||||||
|
handleFeatureLocalClear,
|
||||||
isSoundMuted,
|
isSoundMuted,
|
||||||
loadBlockedSystemSenders,
|
loadBlockedSystemSenders,
|
||||||
normalizeChatPreferences,
|
normalizeChatPreferences,
|
||||||
@@ -440,7 +442,7 @@ import {
|
|||||||
updateRedPacketClaimsUI,
|
updateRedPacketClaimsUI,
|
||||||
} from "./chat-room/red-packet-panel.js";
|
} from "./chat-room/red-packet-panel.js";
|
||||||
import { createMessageQueue } from "./chat-room/message-queue.js";
|
import { createMessageQueue } from "./chat-room/message-queue.js";
|
||||||
import { isExpiredChatImageMessage } from "./chat-room/message-utils.js";
|
import { isExpiredChatImageMessage, localClearScreen } from "./chat-room/message-utils.js";
|
||||||
|
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
// 保留聚合入口,给新迁移模块、测试和仍在 Blade 内的存量脚本统一读取工具。
|
// 保留聚合入口,给新迁移模块、测试和仍在 Blade 内的存量脚本统一读取工具。
|
||||||
@@ -636,6 +638,7 @@ if (typeof window !== "undefined") {
|
|||||||
bindSoundMuteControl,
|
bindSoundMuteControl,
|
||||||
closeDailyStatusEditor,
|
closeDailyStatusEditor,
|
||||||
closeFeatureMenu,
|
closeFeatureMenu,
|
||||||
|
handleFeatureLocalClear,
|
||||||
isSoundMuted,
|
isSoundMuted,
|
||||||
loadBlockedSystemSenders,
|
loadBlockedSystemSenders,
|
||||||
normalizeChatPreferences,
|
normalizeChatPreferences,
|
||||||
@@ -666,12 +669,14 @@ if (typeof window !== "undefined") {
|
|||||||
updateRedPacketClaimsUI,
|
updateRedPacketClaimsUI,
|
||||||
createMessageQueue,
|
createMessageQueue,
|
||||||
isExpiredChatImageMessage,
|
isExpiredChatImageMessage,
|
||||||
|
localClearScreen,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 直接挂载只服务暂未迁移的 Blade 调用点;新代码优先通过模块导入或 ChatRoomTools 复用。
|
// 直接挂载只服务暂未迁移的 Blade 调用点;新代码优先通过模块导入或 ChatRoomTools 复用。
|
||||||
window.closeChatImageLightbox = closeChatImageLightbox;
|
window.closeChatImageLightbox = closeChatImageLightbox;
|
||||||
window.escapeHtml = escapeHtml;
|
window.escapeHtml = escapeHtml;
|
||||||
window.isExpiredChatImageMessage = isExpiredChatImageMessage;
|
window.isExpiredChatImageMessage = isExpiredChatImageMessage;
|
||||||
|
window.localClearScreen = localClearScreen;
|
||||||
window.normalizeSafeChatUrl = normalizeSafeChatUrl;
|
window.normalizeSafeChatUrl = normalizeSafeChatUrl;
|
||||||
window.openChatImageLightbox = openChatImageLightbox;
|
window.openChatImageLightbox = openChatImageLightbox;
|
||||||
window.closeFriendPanel = closeFriendPanel;
|
window.closeFriendPanel = closeFriendPanel;
|
||||||
|
|||||||
@@ -38,3 +38,43 @@ export function isExpiredChatImageMessage(
|
|||||||
|
|
||||||
return nowTimestamp >= sentAt.getTime() + retentionDays * 24 * 60 * 60 * 1000;
|
return nowTimestamp >= sentAt.getTime() + retentionDays * 24 * 60 * 60 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只清理当前浏览器的聊天窗口,并记录本地清屏的最大消息 ID。
|
||||||
|
*
|
||||||
|
* @param {number|string} roomId 房间 ID
|
||||||
|
* @param {number|string} maxMessageId 当前已接收最大消息 ID
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export function localClearScreen(roomId = window.chatContext?.roomId, maxMessageId = 0) {
|
||||||
|
const publicPane = document.getElementById("chat-messages-container");
|
||||||
|
const privatePane = document.getElementById("chat-messages-container2");
|
||||||
|
|
||||||
|
if (publicPane) {
|
||||||
|
publicPane.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (privatePane) {
|
||||||
|
privatePane.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新页面时只恢复本地清屏点之后的新消息,避免旧消息重新回流。
|
||||||
|
localStorage.setItem(`local_clear_msg_id_${roomId}`, maxMessageId);
|
||||||
|
|
||||||
|
const notice = document.createElement("div");
|
||||||
|
notice.className = "msg-line";
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const timeText = [
|
||||||
|
now.getHours().toString().padStart(2, "0"),
|
||||||
|
now.getMinutes().toString().padStart(2, "0"),
|
||||||
|
now.getSeconds().toString().padStart(2, "0"),
|
||||||
|
].join(":");
|
||||||
|
|
||||||
|
notice.innerHTML = `<span style="color: #64748b; font-weight: bold;">🧹 您已执行本地清屏</span><span class="msg-time">(${timeText})</span>`;
|
||||||
|
|
||||||
|
if (publicPane) {
|
||||||
|
publicPane.appendChild(notice);
|
||||||
|
publicPane.scrollTop = publicPane.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -296,6 +296,20 @@ export function toggleBlockMenu(event = null, beforeToggle = undefined) {
|
|||||||
menu.style.display = menu.style.display === "none" ? "block" : "none";
|
menu.style.display = menu.style.display === "none" ? "block" : "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行功能菜单里的本地清屏动作,并在执行前关闭菜单。
|
||||||
|
*
|
||||||
|
* @param {() => void} onLocalClear 本地清屏回调
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export function handleFeatureLocalClear(onLocalClear) {
|
||||||
|
closeFeatureMenu();
|
||||||
|
|
||||||
|
if (typeof onLocalClear === "function") {
|
||||||
|
onLocalClear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定功能菜单、每日状态编辑与系统播报屏蔽的统一事件代理。
|
* 绑定功能菜单、每日状态编辑与系统播报屏蔽的统一事件代理。
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3608,19 +3608,18 @@
|
|||||||
// ── 本地清屏(仅限自己的屏幕)───────────────────────────
|
// ── 本地清屏(仅限自己的屏幕)───────────────────────────
|
||||||
|
|
||||||
function localClearScreen() {
|
function localClearScreen() {
|
||||||
// 清理公聊窗口
|
|
||||||
const say1 = document.getElementById('chat-messages-container');
|
|
||||||
if (say1) say1.innerHTML = '';
|
|
||||||
|
|
||||||
// 清理包厢窗口
|
|
||||||
const say2 = document.getElementById('chat-messages-container2');
|
|
||||||
if (say2) say2.innerHTML = '';
|
|
||||||
lastAutosaveNode = null;
|
lastAutosaveNode = null;
|
||||||
|
if (window.ChatRoomTools?.localClearScreen) {
|
||||||
|
window.ChatRoomTools.localClearScreen(window.chatContext.roomId, _maxMsgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 将当前最大消息 ID 保存至本地,刷新时只显示大于此 ID 的历史记录
|
const say1 = document.getElementById('chat-messages-container');
|
||||||
|
const say2 = document.getElementById('chat-messages-container2');
|
||||||
|
if (say1) say1.innerHTML = '';
|
||||||
|
if (say2) say2.innerHTML = '';
|
||||||
localStorage.setItem(`local_clear_msg_id_${window.chatContext.roomId}`, _maxMsgId);
|
localStorage.setItem(`local_clear_msg_id_${window.chatContext.roomId}`, _maxMsgId);
|
||||||
|
|
||||||
// 插入清屏提示
|
|
||||||
const sysDiv = document.createElement('div');
|
const sysDiv = document.createElement('div');
|
||||||
sysDiv.className = 'msg-line';
|
sysDiv.className = 'msg-line';
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@@ -3638,6 +3637,11 @@
|
|||||||
* 在状态面板中触发本地清屏,并顺手关闭面板。
|
* 在状态面板中触发本地清屏,并顺手关闭面板。
|
||||||
*/
|
*/
|
||||||
function handleFeatureLocalClear() {
|
function handleFeatureLocalClear() {
|
||||||
|
if (window.ChatRoomTools?.handleFeatureLocalClear) {
|
||||||
|
window.ChatRoomTools.handleFeatureLocalClear(localClearScreen);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
closeFeatureMenu();
|
closeFeatureMenu();
|
||||||
localClearScreen();
|
localClearScreen();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user