ssb: prettier.

This commit is contained in:
Cory McWilliams 2024-12-23 11:08:27 -05:00
parent 5051cecb84
commit eb6753afe1
3 changed files with 62 additions and 53 deletions

View File

@ -155,9 +155,15 @@ export async function picker(callback, anchor, author) {
<style> <style>
${styles} ${styles}
</style> </style>
<div class="w3-modal" style="display: block; box-sizing: border-box; z-index: 10"> <div
class="w3-modal"
style="display: block; box-sizing: border-box; z-index: 10"
>
<div class="w3-modal-content w3-card-4"> <div class="w3-modal-content w3-card-4">
<div class="w3-content w3-theme-d1" style="display: flex; flex-direction: column; max-height: 50vh"> <div
class="w3-content w3-theme-d1"
style="display: flex; flex-direction: column; max-height: 50vh"
>
<header class="w3-container" style="flex: 0 0"> <header class="w3-container" style="flex: 0 0">
<h1>Choose a Reaction</h1> <h1>Choose a Reaction</h1>
<span class="w3-button w3-display-topright" @click=${cleanup} <span class="w3-button w3-display-topright" @click=${cleanup}

View File

@ -271,10 +271,13 @@ class TfElement extends LitElement {
} }
async get_latest_private(following) { async get_latest_private(following) {
let latest = (await tfrpc.rpc.query('SELECT MAX(rowid) AS latest FROM messages'))[0].latest; let latest = (
await tfrpc.rpc.query('SELECT MAX(rowid) AS latest FROM messages')
)[0].latest;
const k_chunk_count = 256; const k_chunk_count = 256;
while (latest - k_chunk_count >= 0) { while (latest - k_chunk_count >= 0) {
let messages = await tfrpc.rpc.query(` let messages = await tfrpc.rpc.query(
`
SELECT messages.rowid, messages.id, previous, author, sequence, timestamp, hash, json(content) AS content, signature SELECT messages.rowid, messages.id, previous, author, sequence, timestamp, hash, json(content) AS content, signature
FROM messages FROM messages
JOIN json_each(?1) AS following ON messages.author = following.value JOIN json_each(?1) AS following ON messages.author = following.value
@ -284,17 +287,14 @@ class TfElement extends LitElement {
json(messages.content) LIKE '"%' json(messages.content) LIKE '"%'
ORDER BY sequence DESC ORDER BY sequence DESC
`, `,
[ [JSON.stringify(following), latest - k_chunk_count, latest]
JSON.stringify(following), );
latest - k_chunk_count, messages = (await this.decrypt(messages)).filter((x) => x.decrypted);
latest,
]);
messages = (await this.decrypt(messages)).filter(x => x.decrypted);
if (messages.length) { if (messages.length) {
return Math.max(...messages.map(x => x.rowid)); return Math.max(...messages.map((x) => x.rowid));
} }
latest -= k_chunk_count; latest -= k_chunk_count;
}; }
return -1; return -1;
} }
@ -331,8 +331,10 @@ class TfElement extends LitElement {
console.log('unread', this.channels_unread); console.log('unread', this.channels_unread);
console.log('channels took', (new Date() - start_time) / 1000.0); console.log('channels took', (new Date() - start_time) / 1000.0);
let self = this; let self = this;
latest_private.then(function(latest) { latest_private.then(function (latest) {
self.channels_latest = Object.assign({}, self.channels_latest, {'🔐': latest}); self.channels_latest = Object.assign({}, self.channels_latest, {
'🔐': latest,
});
console.log('private took', (new Date() - start_time) / 1000.0); console.log('private took', (new Date() - start_time) / 1000.0);
}); });
} finally { } finally {
@ -398,26 +400,28 @@ class TfElement extends LitElement {
async decrypt(messages) { async decrypt(messages) {
let whoami = this.whoami; let whoami = this.whoami;
return Promise.all(messages.map(async function (message) { return Promise.all(
let content; messages.map(async function (message) {
try { let content;
content = JSON.parse(message?.content);
} catch {}
if (typeof content === 'string') {
let decrypted;
try { try {
decrypted = await tfrpc.rpc.try_decrypt(whoami, content); content = JSON.parse(message?.content);
} catch {} } catch {}
if (decrypted) { if (typeof content === 'string') {
let decrypted;
try { try {
message.decrypted = JSON.parse(decrypted); decrypted = await tfrpc.rpc.try_decrypt(whoami, content);
} catch { } catch {}
message.decrypted = decrypted; if (decrypted) {
try {
message.decrypted = JSON.parse(decrypted);
} catch {
message.decrypted = decrypted;
}
} }
} }
} return message;
return message; })
})); );
} }
render_tab() { render_tab() {

View File

@ -199,30 +199,29 @@ class TfNewsElement extends LitElement {
return html` return html`
<div> <div>
${final_messages.map( ${final_messages.map(
(x) => (x) => html`
html` <tf-message
<tf-message .message=${x}
.message=${x} whoami=${this.whoami}
whoami=${this.whoami} .users=${this.users}
.users=${this.users} .drafts=${this.drafts}
.drafts=${this.drafts} .expanded=${this.expanded}
.expanded=${this.expanded} collapsed="true"
collapsed="true" channel=${this.channel}
channel=${this.channel} channel_unread=${this.channel_unread}
channel_unread=${this.channel_unread} ></tf-message>
></tf-message> ${x.rowid == unread_rowid && x != final_messages[0]
${x.rowid == unread_rowid && x != final_messages[0] ? html`<div style="display: flex; flex-direction: row">
? html`<div style="display: flex; flex-direction: row"> <div
<div style="border-bottom: 1px solid #f00; flex: 1; align-self: center; height: 1px"
style="border-bottom: 1px solid #f00; flex: 1; align-self: center; height: 1px" ></div>
></div> <div style="color: #f00; padding: 8px">unread</div>
<div style="color: #f00; padding: 8px">unread</div> <div
<div style="border-bottom: 1px solid #f00; flex: 1; align-self: center; height: 1px"
style="border-bottom: 1px solid #f00; flex: 1; align-self: center; height: 1px" ></div>
></div> </div>`
</div>` : undefined}
: undefined} `
`
)} )}
</div> </div>
`; `;