修复:重写本地清屏逻辑,使用 localStorage 记录拉取游标,避免进房带历史功能导致清屏失效

This commit is contained in:
2026-02-28 11:20:34 +08:00
parent 9a98bdfbe6
commit 28d402d204
3 changed files with 42 additions and 3 deletions

View File

@@ -108,11 +108,16 @@
<script>
document.addEventListener('DOMContentLoaded', () => {
const historyMsgs = @json($historyMessages);
const clearId = parseInt(localStorage.getItem(`local_clear_msg_id_{{ $room->id }}`) || '0', 10);
if (historyMsgs && historyMsgs.length > 0) {
// 全局函数 appendMessage 在 scripts.blade.php 中定义
historyMsgs.forEach(msg => {
if (typeof window.appendMessage === 'function') {
window.appendMessage(msg);
// 如果开启了本地清屏,之前的历史记录不再显示
if (msg.id > clearId) {
if (typeof window.appendMessage === 'function') {
window.appendMessage(msg);
}
}
});
}