aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-03-02 00:29:14 +0300
committerRblSb <msrblsb@gmail.com>2025-03-02 00:29:14 +0300
commit3b22ce9b59e1e549dddbba99b90b87a1dc1fcf87 (patch)
tree571e1cf428cdacfa41c88d73ef87ec31ac5169a5
parentf267adf53fbfa8f53bb3e85c5af5e8b925ae8cdc (diff)
Fix chat message skips on limit
I messed up after reversing chat
-rw-r--r--res/client.js24
-rw-r--r--src/client/Main.hx19
2 files changed, 33 insertions, 10 deletions
diff --git a/res/client.js b/res/client.js
index fa4631f..31cca3e 100644
--- a/res/client.js
+++ b/res/client.js
@@ -1679,7 +1679,7 @@ client_Main.prototype = {
var data = JSON.parse(e.data);
if(this.config != null && this.config.isVerbose) {
var t = data.type;
- haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 459, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]});
+ haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 460, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]});
}
client_JsApi.fireEvents(data);
switch(data.type) {
@@ -2196,7 +2196,7 @@ client_Main.prototype = {
}
,chatMessageConnected: function() {
if(this.isLastMessageConnectionStatus()) {
- this.msgBuf.removeChild(this.msgBuf.lastChild);
+ this.msgBuf.removeChild(this.getLastMessageDiv());
}
var div = window.document.createElement("div");
div.className = "server-msg-reconnect";
@@ -2206,7 +2206,7 @@ client_Main.prototype = {
}
,chatMessageDisconnected: function() {
if(this.isLastMessageConnectionStatus()) {
- this.msgBuf.removeChild(this.msgBuf.lastChild);
+ this.msgBuf.removeChild(this.getLastMessageDiv());
}
var div = window.document.createElement("div");
div.className = "server-msg-disconnect";
@@ -2215,7 +2215,7 @@ client_Main.prototype = {
this.scrollChatToEnd();
}
,isLastMessageConnectionStatus: function() {
- var tmp = this.msgBuf.lastElementChild;
+ var tmp = this.getLastMessageDiv();
if(tmp != null) {
return StringTools.startsWith(tmp.className,"server-msg");
} else {
@@ -2318,7 +2318,7 @@ client_Main.prototype = {
userDiv.appendChild(textDiv);
this.addMessageDiv(userDiv);
if(inChatEnd) {
- while(this.msgBuf.children.length > 200) this.msgBuf.removeChild(this.msgBuf.firstChild);
+ while(this.msgBuf.children.length > 200) this.msgBuf.removeChild(this.getFirstMessageDiv());
}
if(inChatEnd || name == this.personal.name) {
this.scrollChatToEnd();
@@ -2329,6 +2329,20 @@ client_Main.prototype = {
this.blinkTabWithTitle("*" + Lang.get("chat") + "*");
}
}
+ ,getFirstMessageDiv: function() {
+ if(this.isMessageBufferReversed()) {
+ return this.msgBuf.lastElementChild;
+ } else {
+ return this.msgBuf.firstElementChild;
+ }
+ }
+ ,getLastMessageDiv: function() {
+ if(this.isMessageBufferReversed()) {
+ return this.msgBuf.firstElementChild;
+ } else {
+ return this.msgBuf.lastElementChild;
+ }
+ }
,addMessageDiv: function(userDiv) {
if(this.isMessageBufferReversed()) {
this.msgBuf.prepend(userDiv);
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);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage