ssb: Load and show new messages as they arrive.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled

This commit is contained in:
2024-12-29 13:32:37 -05:00
parent baf125c450
commit eca8726909
4 changed files with 22 additions and 46 deletions

View File

@ -8,7 +8,6 @@ class TfTabNewsElement extends LitElement {
whoami: {type: String},
users: {type: Object},
hash: {type: String},
unread: {type: Array},
following: {type: Array},
drafts: {type: Object},
expanded: {type: Object},
@ -27,7 +26,6 @@ class TfTabNewsElement extends LitElement {
this.whoami = null;
this.users = {};
this.hash = '#';
this.unread = [];
this.following = [];
this.cache = {};
this.drafts = {};
@ -50,36 +48,13 @@ class TfTabNewsElement extends LitElement {
document.body.removeEventListener('keypress', this.on_keypress.bind(this));
}
show_more() {
let unread = this.unread;
load_latest() {
let news = this.shadowRoot?.getElementById('news');
if (news) {
news.load_latest();
this.dispatchEvent(new CustomEvent('refresh'));
}
}
new_messages_text() {
if (!this.unread?.length) {
return 'No new messages.';
}
let counts = {};
for (let message of this.unread) {
let type = 'private';
try {
type = JSON.parse(message.content).type || type;
} catch {}
counts[type] = (counts[type] || 0) + 1;
}
return (
'↻ Show New: ' +
Object.keys(counts)
.sort()
.map((x) => counts[x].toString() + ' ' + x + 's')
.join(', ')
);
}
draft(event) {
let id = event.detail.id || '';
let previous = this.drafts[id];
@ -245,7 +220,11 @@ class TfTabNewsElement extends LitElement {
id="sidebar_overlay"
@click=${this.hide_sidebar}
></div>
<div style="margin-left: 2in; padding: 0px; top: 0; max-height: 100%; overflow: scroll" id="main" class="w3-main">
<div
style="margin-left: 2in; padding: 0px; top: 0; max-height: 100%; overflow: scroll"
id="main"
class="w3-main"
>
<div style="padding: 8px">
<div
id="show_sidebar"
@ -255,9 +234,6 @@ class TfTabNewsElement extends LitElement {
&#9776;
</div>
<p>
<button class="w3-button w3-theme-d1" @click=${this.show_more}>
${this.new_messages_text()}
</button>
${this.hash.startsWith('##')
? html`
<button