ssb: A more plausibly correct way to load new messages correctly.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 14m51s

This commit is contained in:
Cory McWilliams 2024-12-01 18:20:57 -05:00
parent 6fe6fc180d
commit 91ad43fdfc
3 changed files with 18 additions and 9 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🐌", "emoji": "🐌",
"previous": "&HvktcPAoPEAMafJDMGKe7PQQID9wMsAEpSLeoG75hJk=.sha256" "previous": "&kAAjuIOpPmvwRqQKyFIexrTclB3vLAWGwfDgRy16npA=.sha256"
} }

View File

@ -191,13 +191,25 @@ class TfTabNewsFeedElement extends LitElement {
return result; return result;
} }
async add_messages(messages) { async load_latest() {
this.messages = await this.decrypt([...messages, ...this.messages]); this.loading++;
let now = new Date().valueOf();
let end_time = now + 24 * 60 * 60 * 1000;
let messages = [];
try {
messages = await this.fetch_messages(this.time_range[1], end_time);
messages = await this.decrypt(messages);
this.time_range = [this.time_range[0], end_time];
} finally {
this.loading--;
}
this.messages = [...this.messages, ...messages];
console.log('done loading latest messages.');
} }
async load_messages() { async load_messages() {
let self = this; let self = this;
this.loading = true; this.loading++;
let messages = []; let messages = [];
try { try {
this.messages = []; this.messages = [];
@ -220,7 +232,7 @@ class TfTabNewsFeedElement extends LitElement {
messages = await this.decrypt([...more, ...this.messages]); messages = await this.decrypt([...more, ...this.messages]);
} }
} finally { } finally {
this.loading = false; this.loading--;
} }
this.messages = messages; this.messages = messages;
console.log(`loading messages done for ${self.whoami}`); console.log(`loading messages done for ${self.whoami}`);

View File

@ -54,10 +54,7 @@ class TfTabNewsElement extends LitElement {
let unread = this.unread; let unread = this.unread;
let news = this.shadowRoot?.getElementById('news'); let news = this.shadowRoot?.getElementById('news');
if (news) { if (news) {
console.log('injecting messages', news.messages); news.load_latest();
news.add_messages(
Object.values(Object.fromEntries(this.unread.map((x) => [x.id, x])))
);
this.dispatchEvent(new CustomEvent('refresh')); this.dispatchEvent(new CustomEvent('refresh'));
} }
} }