ssb: Try harder to avoid a full re-render. It's disruptive.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
This commit is contained in:
parent
003e0caada
commit
0d597721bf
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🦀",
|
||||
"previous": "&xWW9fuitFr6jFhe4fopPq2Zuu08ZBzHoKjFAAPx2a/U=.sha256"
|
||||
"previous": "&N69/NfCoe/HmdG5Hl/ulq/CDYLhDYzi50jbg2h3VPuc=.sha256"
|
||||
}
|
||||
|
@ -274,6 +274,11 @@ class TfTabNewsFeedElement extends LitElement {
|
||||
return result;
|
||||
}
|
||||
|
||||
merge_messages(old_messages, new_messages) {
|
||||
let old_by_id = Object.fromEntries(old_messages.map(x => [x.id, x]));
|
||||
return new_messages.map(x => old_by_id[x.id] ? old_by_id[x.id] : x);
|
||||
}
|
||||
|
||||
async load_latest() {
|
||||
this.loading++;
|
||||
let now = new Date().valueOf();
|
||||
@ -293,14 +298,14 @@ class TfTabNewsFeedElement extends LitElement {
|
||||
} finally {
|
||||
this.loading--;
|
||||
}
|
||||
this.messages = Object.values(
|
||||
this.messages = this.merge_messages(this.messages, Object.values(
|
||||
Object.fromEntries(
|
||||
[...this.messages, ...messages]
|
||||
.sort((x, y) => x.timestamp - y.timestamp)
|
||||
.slice(-1024)
|
||||
.map((x) => [x.id, x])
|
||||
)
|
||||
);
|
||||
));
|
||||
console.log('done loading latest messages.');
|
||||
}
|
||||
|
||||
@ -309,8 +314,10 @@ class TfTabNewsFeedElement extends LitElement {
|
||||
this.loading++;
|
||||
let messages = [];
|
||||
try {
|
||||
this.messages = [];
|
||||
this._messages_hash = this.hash;
|
||||
if (this._messages_hash !== this.hash) {
|
||||
this.messages = [];
|
||||
this._messages_hash = this.hash;
|
||||
}
|
||||
this._messages_following = this.following;
|
||||
let now = new Date().valueOf();
|
||||
let start_time = now - 24 * 60 * 60 * 1000;
|
||||
@ -345,7 +352,7 @@ class TfTabNewsFeedElement extends LitElement {
|
||||
} finally {
|
||||
this.loading--;
|
||||
}
|
||||
this.messages = messages;
|
||||
this.messages = this.merge_messages(this.messages, messages);
|
||||
this.time_loading = undefined;
|
||||
console.log(`loading messages done for ${self.whoami}`);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user