From 7da3244da28241f68cff4342a2964537a265defb Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 5 Dec 2024 20:47:02 -0500 Subject: [PATCH] ssb: prettier. --- apps/ssb/tf-app.js | 38 +++++++---- apps/ssb/tf-compose.js | 6 +- apps/ssb/tf-message.js | 37 +++++++---- apps/ssb/tf-news.js | 39 ++++++----- apps/ssb/tf-tab-news-feed.js | 64 ++++++++++++------ apps/ssb/tf-tab-news.js | 124 ++++++++++++++++++++++++----------- 6 files changed, 201 insertions(+), 107 deletions(-) diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index a95842a4d..521337c7b 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -72,7 +72,8 @@ class TfElement extends LitElement { } async load_channels() { - let channels = await tfrpc.rpc.query(` + let channels = await tfrpc.rpc.query( + ` SELECT content ->> 'channel' AS channel, content ->> 'subscribed' AS subscribed @@ -82,7 +83,9 @@ class TfElement extends LitElement { author = ? AND content ->> 'type' = 'channel' ORDER BY sequence - `, [this.whoami]); + `, + [this.whoami] + ); let channel_map = {}; for (let row of channels) { if (row.subscribed) { @@ -243,7 +246,8 @@ class TfElement extends LitElement { }; by_count.push({count: v.of, id: id}); } - let channels = tfrpc.rpc.query(` + let channels = tfrpc.rpc.query( + ` SELECT channels.value AS channel, MAX(messages.rowid) AS rowid FROM messages JOIN json_each(?1) AS channels ON messages.content ->> 'channel' = channels.value JOIN json_each(?2) AS following ON messages.author = following.value @@ -257,12 +261,16 @@ class TfElement extends LitElement { SELECT '@' AS channel, MAX(messages.rowid) AS rowid FROM messages_fts(?3) JOIN messages ON messages.rowid = messages_fts.rowid JOIN json_each(?2) AS following ON messages.author = following.value - `, [ - JSON.stringify(this.channels), - JSON.stringify(Object.keys(following)), - '"' + this.whoami.replace('"', '""') + '"', - ]); - this.channels_unread = JSON.parse((await tfrpc.rpc.databaseGet('unread')) ?? '{}'); + `, + [ + JSON.stringify(this.channels), + JSON.stringify(Object.keys(following)), + '"' + this.whoami.replace('"', '""') + '"', + ] + ); + this.channels_unread = JSON.parse( + (await tfrpc.rpc.databaseGet('unread')) ?? '{}' + ); let start_time = new Date(); users = await this.fetch_about(Object.keys(following).sort(), users); console.log( @@ -275,7 +283,9 @@ class TfElement extends LitElement { start_time = new Date(); channels = await channels; console.log('channels took', (new Date() - start_time) / 1000.0); - this.channels_latest = Object.fromEntries(channels.map(x => [x.channel, x.rowid])); + this.channels_latest = Object.fromEntries( + channels.map((x) => [x.channel, x.rowid]) + ); this.following = Object.keys(following); this.users = users; console.log(`load finished ${whoami} => ${this.whoami}`); @@ -375,7 +385,10 @@ class TfElement extends LitElement { }; let tabs = html` -
+
`; } diff --git a/apps/ssb/tf-compose.js b/apps/ssb/tf-compose.js index 3b38467cf..7449f26b8 100644 --- a/apps/ssb/tf-compose.js +++ b/apps/ssb/tf-compose.js @@ -537,9 +537,9 @@ class TfComposeElement extends LitElement { class="w3-card-4 w3-theme-d4 w3-padding-small" style="box-sizing: border-box" > - ${this.channel !== undefined ? - html`

To #${this.channel}:

` : - undefined} + ${this.channel !== undefined + ? html`

To #${this.channel}:

` + : undefined} ${this.render_encrypt()}
diff --git a/apps/ssb/tf-message.js b/apps/ssb/tf-message.js index d97a2c5ff..12d30cad3 100644 --- a/apps/ssb/tf-message.js +++ b/apps/ssb/tf-message.js @@ -324,14 +324,16 @@ ${JSON.stringify(mention, null, 2)}= this.channel_unread ? 'w3-theme-d2' : 'w3-theme-d4'); + : this.message?.rowid >= this.channel_unread + ? 'w3-theme-d2' + : 'w3-theme-d4'; let self = this; let raw_button; switch (this.format) { @@ -640,11 +644,16 @@ ${JSON.stringify(content, null, 2)} React - ${(!content.root && this.message.rowid < this.channel_unread) ? - html` - - ` : - undefined} + ${!content.root && this.message.rowid < this.channel_unread + ? html` + + ` + : undefined}

${this.render_children()}
diff --git a/apps/ssb/tf-news.js b/apps/ssb/tf-news.js index 9ea9d3640..fe39dcb66 100644 --- a/apps/ssb/tf-news.js +++ b/apps/ssb/tf-news.js @@ -192,24 +192,27 @@ class TfNewsElement extends LitElement {
${final_messages.map( (x) => - html` - ${x.rowid == unread_rowid && x != final_messages[0] ? - html`
-
-
unread
-
-
` : - undefined} - ` + html` ${x.rowid == unread_rowid && x != final_messages[0] + ? html`
+
+
unread
+
+
` + : undefined} + ` )}
`; diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index d6ab11cb2..4f90dbcc6 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -30,13 +30,15 @@ class TfTabNewsFeedElement extends LitElement { this.drafts = {}; this.expanded = {}; this.channels_unread = {}; - this.start_time = (new Date()).valueOf(); + this.start_time = new Date().valueOf(); this.time_range = [0, 0]; this.loading = 0; } channel() { - return this.hash.startsWith('##') ? this.hash.substring(2) : this.hash.substring(1); + return this.hash.startsWith('##') + ? this.hash.substring(2) + : this.hash.substring(1); } async fetch_messages(start_time, end_time) { @@ -52,12 +54,14 @@ class TfTabNewsFeedElement extends LitElement { messages.timestamp > ?3 AND messages.timestamp < ?4 ORDER BY timestamp DESC limit 20 - `, [ + `, + [ '"' + this.whoami.replace('"', '""') + '"', JSON.stringify(this.following), start_time, end_time, - ]); + ] + ); return r; } else if (this.hash.startsWith('#@')) { let r = await tfrpc.rpc.query( @@ -248,7 +252,10 @@ class TfTabNewsFeedElement extends LitElement { let start_time = now - 24 * 60 * 60 * 1000; this.start_time = start_time; this.time_range = [this.start_time, now + 24 * 60 * 60 * 1000]; - messages = await this.fetch_messages(this.time_range[0], this.time_range[1]); + messages = await this.fetch_messages( + this.time_range[0], + this.time_range[1] + ); messages = await this.decrypt(messages); if (!messages.length) { let more = []; @@ -268,16 +275,21 @@ class TfTabNewsFeedElement extends LitElement { } mark_all_read() { - let newest = this.messages.reduce((accumulator, current) => Math.max(accumulator, current.rowid), -1); + let newest = this.messages.reduce( + (accumulator, current) => Math.max(accumulator, current.rowid), + -1 + ); if (newest >= 0) { - this.dispatchEvent(new CustomEvent('channelsetunread', { - bubbles: true, - composed: true, - detail: { - channel: this.channel(), - unread: newest + 1, - }, - })); + this.dispatchEvent( + new CustomEvent('channelsetunread', { + bubbles: true, + composed: true, + detail: { + channel: this.channel(), + unread: newest + 1, + }, + }) + ); } } @@ -296,19 +308,33 @@ class TfTabNewsFeedElement extends LitElement { if (!this.hash.startsWith('#@') && !this.hash.startsWith('#%')) { more = html`

- - + - - Showing ${new Date(this.time_range[0]).toLocaleDateString()} - ${new Date(this.time_range[1]).toLocaleDateString()}. + Showing ${new Date(this.time_range[0]).toLocaleDateString()} - + ${new Date(this.time_range[1]).toLocaleDateString()}.

`; } return html` - + x != channel); + this.channels = this.channels.filter((x) => x != channel); } } @@ -149,14 +151,15 @@ class TfTabNewsElement extends LitElement { } render() { - let profile = this.hash.startsWith('#@') && this.hash != '#@' - ? html`` - : undefined; + let profile = + this.hash.startsWith('#@') && this.hash != '#@' + ? html`` + : undefined; let edit_profile; if ( !this.loading && @@ -171,41 +174,82 @@ class TfTabNewsElement extends LitElement {
`; } return html` -