From 2597f99ccf243cfc03133d9f72daa44d5c3395e6 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 29 Apr 2025 20:48:47 -0400 Subject: [PATCH] ssb: Get recent reactions up front so that we don't need to delay showing the dialog for them. --- apps/ssb.json | 2 +- apps/ssb/emojis.js | 17 +---------------- apps/ssb/tf-app.js | 18 ++++++++++++++++++ apps/ssb/tf-message.js | 7 ++++++- apps/ssb/tf-news.js | 3 +++ apps/ssb/tf-tab-news-feed.js | 3 +++ apps/ssb/tf-tab-news.js | 3 +++ 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/apps/ssb.json b/apps/ssb.json index b1aebd40..6b886bd1 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&+Hv0lBH8OyyJq/ENWIGw1kpq3zrl56hqophb9vrekjk=.sha256" + "previous": "&JwI2HPmMbibkcF0ll7+mjIaMuSkwxPR3cQXsXhvGp58=.sha256" } diff --git a/apps/ssb/emojis.js b/apps/ssb/emojis.js index 94a5e0c7..5d144541 100644 --- a/apps/ssb/emojis.js +++ b/apps/ssb/emojis.js @@ -14,23 +14,8 @@ function get_emojis() { }); } -async function get_recent(author) { - let recent = await tfrpc.rpc.query( - ` - SELECT DISTINCT content ->> '$.vote.expression' AS value - FROM messages - WHERE author = ? AND - content ->> '$.type' = 'vote' - ORDER BY timestamp DESC LIMIT 10 - `, - [author] - ); - return recent.map((x) => x.value); -} - -export async function picker(callback, anchor, author) { +export async function picker(callback, anchor, author, recent) { let json = await get_emojis(); - let recent = await get_recent(author); let div = document.createElement('div'); div.id = 'emoji_picker'; diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index 2fd44553..3421f097 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -21,6 +21,7 @@ class TfElement extends LitElement { guest: {type: Boolean}, url: {type: String}, private_messages: {type: Array}, + recent_reactions: {type: Array}, }; } @@ -41,6 +42,7 @@ class TfElement extends LitElement { this.channels_latest = {}; this.loading_latest = 0; this.loading_latest_scheduled = 0; + this.recent_reactions = []; tfrpc.rpc.getBroadcasts().then((b) => { self.broadcasts = b || []; }); @@ -452,6 +454,19 @@ class TfElement extends LitElement { return users; } + async load_recent_reactions() { + this.recent_reactions = (await tfrpc.rpc.query( + ` + SELECT DISTINCT content ->> '$.vote.expression' AS value + FROM messages + WHERE author = ? AND + content ->> '$.type' = 'vote' + ORDER BY timestamp DESC LIMIT 10 + `, + [this.whoami] + )).map((x) => x.value); + } + async load() { this.loading_latest = true; try { @@ -469,6 +484,7 @@ class TfElement extends LitElement { }; by_count.push({count: v.of, id: id}); } + let reactions = this.load_recent_reactions(); this.load_channels_latest(Object.keys(following)); this.channels_unread = JSON.parse( (await tfrpc.rpc.databaseGet('unread')) ?? '{}' @@ -494,6 +510,7 @@ class TfElement extends LitElement { console.log( `load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}` ); + await reactions; this.whoami = whoami; this.loaded = whoami; } finally { @@ -551,6 +568,7 @@ class TfElement extends LitElement { @channelsetunread=${this.channel_set_unread} .connections=${this.connections} .private_messages=${this.private_messages} + .recent_reactions=${this.recent_reactions} > `; } else if (this.tab === 'connections') { diff --git a/apps/ssb/tf-message.js b/apps/ssb/tf-message.js index 37edc963..a79b70ea 100644 --- a/apps/ssb/tf-message.js +++ b/apps/ssb/tf-message.js @@ -16,6 +16,7 @@ class TfMessageElement extends LitElement { expanded: {type: Object}, channel: {type: String}, channel_unread: {type: Number}, + recent_reactions: {type: Array}, }; } @@ -31,6 +32,7 @@ class TfMessageElement extends LitElement { this.format = 'message'; this.expanded = {}; this.channel_unread = -1; + this.recent_reactions = []; } connectedCallback() { @@ -155,7 +157,7 @@ class TfMessageElement extends LitElement { } react(event) { - emojis.picker((x) => this.vote(x), null, this.whoami); + emojis.picker((x) => this.vote(x), null, this.whoami, this.recent_reactions); } show_image(link) { @@ -337,6 +339,7 @@ class TfMessageElement extends LitElement { .expanded=${this.expanded} channel=${this.channel} channel_unread=${this.channel_unread} + .recent_reactions=${this.recent_reactions} >` )} @@ -533,6 +536,7 @@ class TfMessageElement extends LitElement { .expanded=${self.expanded} channel=${self.channel} channel_unread=${self.channel_unread} + .recent_reactions=${self.recent_reactions} > ` )} @@ -552,6 +556,7 @@ class TfMessageElement extends LitElement { .drafts=${this.drafts} @tf-discard=${this.discard_reply} author=${this.message.author} + .recent_reactions=${this.recent_reactions} > ` : undefined; diff --git a/apps/ssb/tf-news.js b/apps/ssb/tf-news.js index c7856c74..3e21a1da 100644 --- a/apps/ssb/tf-news.js +++ b/apps/ssb/tf-news.js @@ -13,6 +13,7 @@ class TfNewsElement extends LitElement { expanded: {type: Object}, channel: {type: String}, channel_unread: {type: Number}, + recent_reactions: {type: Array}, }; } @@ -28,6 +29,7 @@ class TfNewsElement extends LitElement { this.drafts = {}; this.expanded = {}; this.channel_unread = -1; + this.recent_reactions = []; } process_messages(messages) { @@ -211,6 +213,7 @@ class TfNewsElement extends LitElement { collapsed="true" channel=${this.channel} channel_unread=${this.channel_unread} + .recent_reactions=${this.recent_reactions} > ${x.rowid == unread_rowid ? html`
diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index 48d1dcee..9e5ea822 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -18,6 +18,7 @@ class TfTabNewsFeedElement extends LitElement { time_range: {type: Array}, time_loading: {type: Array}, private_messages: {type: Array}, + recent_reactions: {type: Array}, }; } @@ -37,6 +38,7 @@ class TfTabNewsFeedElement extends LitElement { this.start_time = new Date().valueOf(); this.time_range = [0, 0]; this.time_loading = undefined; + this.recent_reactions = []; this.loading = 0; } @@ -452,6 +454,7 @@ class TfTabNewsFeedElement extends LitElement { .expanded=${this.expanded} channel=${this.channel()} channel_unread=${this.channels_unread?.[this.channel()]} + .recent_reactions=${this.recent_reactions} > ${more} `); diff --git a/apps/ssb/tf-tab-news.js b/apps/ssb/tf-tab-news.js index 08eb3368..e64f6c9f 100644 --- a/apps/ssb/tf-tab-news.js +++ b/apps/ssb/tf-tab-news.js @@ -24,6 +24,7 @@ class TfTabNewsElement extends LitElement { channels_latest: {type: Object}, connections: {type: Array}, private_messages: {type: Array}, + recent_reactions: {type: Array}, }; } @@ -43,6 +44,7 @@ class TfTabNewsElement extends LitElement { this.channels_latest = {}; this.channels = []; this.connections = []; + this.recent_reactions = []; tfrpc.rpc.localStorageGet('drafts').then(function (d) { self.drafts = JSON.parse(d || '{}'); }); @@ -342,6 +344,7 @@ class TfTabNewsElement extends LitElement { .channels_unread=${this.channels_unread} .channels_latest=${this.channels_latest} .private_messages=${this.private_messages} + .recent_reactions=${this.recent_reactions} >