diff options
| author | RblSb <msrblsb@gmail.com> | 2025-03-02 00:29:14 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2025-03-02 00:29:14 +0300 |
| commit | 3b22ce9b59e1e549dddbba99b90b87a1dc1fcf87 (patch) | |
| tree | 571e1cf428cdacfa41c88d73ef87ec31ac5169a5 /src | |
| parent | f267adf53fbfa8f53bb3e85c5af5e8b925ae8cdc (diff) | |
Fix chat message skips on limit
I messed up after reversing chat
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/Main.hx | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/client/Main.hx b/src/client/Main.hx index 42030dd..8ed519b 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -28,6 +28,7 @@ import js.html.WebSocket; class Main { public static var instance(default, null):Main; static inline var SETTINGS_VERSION = 5; + static inline var MAX_CHAT_MESSAGES = 200; public final settings:ClientSettings; public var isSyncActive = true; @@ -938,7 +939,7 @@ class Main { function chatMessageConnected():Void { if (isLastMessageConnectionStatus()) { - msgBuf.removeChild(msgBuf.lastChild); + msgBuf.removeChild(getLastMessageDiv()); } final div = document.createDivElement(); div.className = "server-msg-reconnect"; @@ -949,7 +950,7 @@ class Main { function chatMessageDisconnected():Void { if (isLastMessageConnectionStatus()) { - msgBuf.removeChild(msgBuf.lastChild); + msgBuf.removeChild(getLastMessageDiv()); } final div = document.createDivElement(); div.className = "server-msg-disconnect"; @@ -959,7 +960,7 @@ class Main { } function isLastMessageConnectionStatus():Bool { - return msgBuf.lastElementChild?.className.startsWith("server-msg"); + return getLastMessageDiv()?.className.startsWith("server-msg"); } public function serverMessage(text:String, isText = true, withTimestamp = true):Element { @@ -1068,8 +1069,8 @@ class Main { addMessageDiv(userDiv); if (inChatEnd) { - while (msgBuf.children.length > 200) { - msgBuf.removeChild(msgBuf.firstChild); + while (msgBuf.children.length > MAX_CHAT_MESSAGES) { + msgBuf.removeChild(getFirstMessageDiv()); } } if (inChatEnd || name == personal.name) { @@ -1080,6 +1081,14 @@ class Main { if (onBlinkTab == null) blinkTabWithTitle('*${Lang.get("chat")}*'); } + function getFirstMessageDiv():Null<Element> { + return isMessageBufferReversed() ? msgBuf.lastElementChild : msgBuf.firstElementChild; + } + + function getLastMessageDiv():Null<Element> { + return isMessageBufferReversed() ? msgBuf.firstElementChild : msgBuf.lastElementChild; + } + function addMessageDiv(userDiv:Element):Void { if (isMessageBufferReversed()) msgBuf.prepend(userDiv); else msgBuf.appendChild(userDiv); |
