diff --git a/apps/ssb.json b/apps/ssb.json index 944fe64c..3908ee46 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🐌", - "previous": "&HvktcPAoPEAMafJDMGKe7PQQID9wMsAEpSLeoG75hJk=.sha256" + "previous": "&kAAjuIOpPmvwRqQKyFIexrTclB3vLAWGwfDgRy16npA=.sha256" } diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index 893d84fe..085de82f 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -191,13 +191,25 @@ class TfTabNewsFeedElement extends LitElement { return result; } - async add_messages(messages) { - this.messages = await this.decrypt([...messages, ...this.messages]); + async load_latest() { + 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() { let self = this; - this.loading = true; + this.loading++; let messages = []; try { this.messages = []; @@ -220,7 +232,7 @@ class TfTabNewsFeedElement extends LitElement { messages = await this.decrypt([...more, ...this.messages]); } } finally { - this.loading = false; + this.loading--; } this.messages = messages; console.log(`loading messages done for ${self.whoami}`); diff --git a/apps/ssb/tf-tab-news.js b/apps/ssb/tf-tab-news.js index e41431a8..443a4435 100644 --- a/apps/ssb/tf-tab-news.js +++ b/apps/ssb/tf-tab-news.js @@ -54,10 +54,7 @@ class TfTabNewsElement extends LitElement { let unread = this.unread; let news = this.shadowRoot?.getElementById('news'); if (news) { - console.log('injecting messages', news.messages); - news.add_messages( - Object.values(Object.fromEntries(this.unread.map((x) => [x.id, x]))) - ); + news.load_latest(); this.dispatchEvent(new CustomEvent('refresh')); } }