From 63c2a808162475b2f7f1677e05f4d89de99f0b65 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 20 Sep 2022 23:03:28 +0300 Subject: [PATCH] fix message list recomputation --- frontend/src/stores.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frontend/src/stores.js b/frontend/src/stores.js index d31729d..3305f87 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -174,7 +174,9 @@ class MessageStore extends Store { } _recomputeMessages() { - this.value = this.value.map((e, i) => this._processMessage(e, this.value[i - 1])); + for (let i = 0; i < this.value.length; i++) { + this.value[i] = this._processMessage(this.value[i], this.value[i - 1]); + } } _processMessage(message, previous=null) { @@ -262,10 +264,11 @@ class MessageStore extends Store { if (!this.isCollectingOldMessages) return false; - const target = 50; + const target = 25; const delta = this.value.length - target; if (delta >= 1) { this.value.splice(0, delta); + this._recomputeMessages(); this.updated(); return true; } else { @@ -291,12 +294,8 @@ class MessageStore extends Store { if (beforeCommitToStore) beforeCommitToStore(res.json); res.json.reverse(); - for (let i = 0; i < res.json.length; i++) { - const message = res.json[i]; - const previous = res.json[i - 1]; - res.json[i] = this._processMessage(message, previous); - } this.value = res.json.concat(this.value); + this._recomputeMessages(); this.updated(); } else { overlayStore.toast("Messages failed to load");