fix message list recomputation

This commit is contained in:
hippoz 2022-09-20 23:03:28 +03:00
parent 265af195da
commit 63c2a80816
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -174,7 +174,9 @@ class MessageStore extends Store {
} }
_recomputeMessages() { _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) { _processMessage(message, previous=null) {
@ -262,10 +264,11 @@ class MessageStore extends Store {
if (!this.isCollectingOldMessages) if (!this.isCollectingOldMessages)
return false; return false;
const target = 50; const target = 25;
const delta = this.value.length - target; const delta = this.value.length - target;
if (delta >= 1) { if (delta >= 1) {
this.value.splice(0, delta); this.value.splice(0, delta);
this._recomputeMessages();
this.updated(); this.updated();
return true; return true;
} else { } else {
@ -291,12 +294,8 @@ class MessageStore extends Store {
if (beforeCommitToStore) if (beforeCommitToStore)
beforeCommitToStore(res.json); beforeCommitToStore(res.json);
res.json.reverse(); 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.value = res.json.concat(this.value);
this._recomputeMessages();
this.updated(); this.updated();
} else { } else {
overlayStore.toast("Messages failed to load"); overlayStore.toast("Messages failed to load");