ssb: prettier.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 16m29s

This commit is contained in:
2024-12-05 20:47:02 -05:00
parent bfeb0c2988
commit 7da3244da2
6 changed files with 201 additions and 107 deletions

View File

@ -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`
<p>
<button class="w3-button w3-theme-d1" @click=${this.mark_all_read}>Mark All Read</button>
<button ?disabled=${this.loading} class="w3-button w3-theme-d1" @click=${this.load_more}>
<button class="w3-button w3-theme-d1" @click=${this.mark_all_read}>
Mark All Read
</button>
<button
?disabled=${this.loading}
class="w3-button w3-theme-d1"
@click=${this.load_more}
>
Load More
</button>
<button class=${'w3-button w3-theme-d1' + (this.loading ? '' : ' w3-hide')} @click=${this.cancel_load}>
<button
class=${'w3-button w3-theme-d1' + (this.loading ? '' : ' w3-hide')}
@click=${this.cancel_load}
>
Cancel
</button>
<span>Showing ${new Date(this.time_range[0]).toLocaleDateString()} - ${new Date(this.time_range[1]).toLocaleDateString()}.</span>
<span
>Showing ${new Date(this.time_range[0]).toLocaleDateString()} -
${new Date(this.time_range[1]).toLocaleDateString()}.</span
>
</p>
`;
}
return html`
<button class="w3-button w3-theme-d1" @click=${this.mark_all_read}>Mark All Read</button>
<button class="w3-button w3-theme-d1" @click=${this.mark_all_read}>
Mark All Read
</button>
<tf-news
id="news"
whoami=${this.whoami}