diff --git a/apps/ssb.json b/apps/ssb.json index fe36afe7..53ef165c 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&LdCd9+kl1DTJIE1+wJ20Yrtpbm15aXvjIBJU3r5Fi38=.sha256" + "previous": "&cnc92v8+8JMxSIvs6vZ6j01rUzyVtKg6zkITqwQ02Lc=.sha256" } diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index cd2e7be4..367842ce 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -46,7 +46,6 @@ class TfTabNewsFeedElement extends LitElement { } async fetch_messages(start_time, end_time) { - console.log('fetch_messages', this.hash, start_time, end_time); this.time_loading = [start_time, end_time]; let result; if (this.hash == '#@') { @@ -58,7 +57,7 @@ class TfTabNewsFeedElement extends LitElement { JOIN json_each(?2) AS following ON messages.author = following.value WHERE messages.author != ?1 AND - ?3 IS NULL OR (messages.timestamp >= ?3 AND messages.timestamp < ?4) + (?3 IS NULL OR messages.timestamp >= ?3) AND messages.timestamp < ?4 ORDER BY timestamp DESC limit 20) SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature FROM mentions @@ -78,12 +77,9 @@ class TfTabNewsFeedElement extends LitElement { result = await tfrpc.rpc.query( ` WITH - mine AS (SELECT rowid, id, previous, author, sequence, timestamp, hash, json(content) AS content, signature + selected AS (SELECT rowid, id, previous, author, sequence, timestamp, hash, json(content) AS content, signature FROM messages - WHERE messages.author = ?), - selected AS ( - SELECT * FROM mine - WHERE ?2 IS NULL OR (mine.timestamp >= 2 AND mine.timestamp < ?3) + WHERE messages.author = ?1 AND (?2 IS NULL OR messages.timestamp >= 2) AND messages.timestamp < ?3 ORDER BY sequence DESC LIMIT 20 ) SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature @@ -129,7 +125,7 @@ class TfTabNewsFeedElement extends LitElement { JOIN json_each(?1) AS following ON messages.author = following.value JOIN json_tree(messages.content, '$.mentions') AS mention ON mention.value = '#' || ?4), news AS (SELECT * FROM all_news - WHERE ?2 IS NULL OR (all_news.timestamp >= ?2 AND all_news.timestamp < ?3) + WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 ORDER BY all_news.timestamp DESC LIMIT 20) SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature FROM news @@ -161,7 +157,7 @@ class TfTabNewsFeedElement extends LitElement { FROM messages JOIN json_each(?1) AS following ON messages.author = following.value WHERE - ?2 IS NULL OR (messages.timestamp >= ?2 AND messages.timestamp < ?3) AND + (?2 IS NULL OR (messages.timestamp >= ?2) AND messages.timestamp < ?3 AND json(messages.content) LIKE '"%' ORDER BY sequence DESC LIMIT 20 `, @@ -179,7 +175,7 @@ class TfTabNewsFeedElement extends LitElement { WHERE timestamp >= 0 AND timestamp < ?3), news AS ( SELECT * FROM all_news - WHERE ?2 IS NULL or (all_news.timestamp >= ?2 AND all_news.timestamp < ?3) + WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 ORDER BY timestamp DESC LIMIT 20 ) SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature @@ -224,17 +220,13 @@ class TfTabNewsFeedElement extends LitElement { this.loading_canceled = false; try { let more = []; - while (!more.length && !this.loading_canceled) { - let last_start_time = this.start_time; - this.start_time = last_start_time - 7 * 24 * 60 * 60 * 1000; - more = await this.fetch_messages(this.start_time, last_start_time); - this.update_time_range_from_messages( - more.filter( - (x) => - x.timestamp >= this.start_time && x.timestamp < last_start_time - ) - ); - } + let last_start_time = this.time_range[0]; + more = await this.fetch_messages(null, last_start_time); + this.update_time_range_from_messages( + more.filter( + (x) => x.timestamp < last_start_time + ) + ); this.messages = await this.decrypt([...more, ...this.messages]); } finally { this.loading--;