From 478bbed1b9d38b036142f642fef89aeb773093da Mon Sep 17 00:00:00 2001 From: Mitchdev Date: Sun, 8 Dec 2024 02:01:47 +1300 Subject: [PATCH] Make sure there is at least 150 history messages in the message array. --- assets/chat/js/window.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/window.js b/assets/chat/js/window.js index 7c965b3b..4dcc8019 100644 --- a/assets/chat/js/window.js +++ b/assets/chat/js/window.js @@ -122,9 +122,26 @@ class ChatWindow extends EventEmitter { remove.forEach((element) => { element.remove(); }); - - this.messages = this.messages.slice(lines.length - this.maxlines); } + + let clientMessages = 0; + this.messages = this.messages + .reverse() + .filter((message, index) => { + if (clientOnlyMessages.includes(message.type)) { + clientMessages += 1; + // remove client only messages if above maxlines + if (index >= this.maxlines) { + return false; + } + // remove history message if above maxlines/maxhistory + the clientMessages + } else if (index >= Math.max(this.maxlines, 150) + clientMessages) { + return false; + } + + return true; + }) + .reverse(); } }