From 3ca2b195021a85857fd16df2b45f2170fe41e2cb Mon Sep 17 00:00:00 2001
From: Cory McWilliams
Date: Sat, 30 Nov 2024 17:49:27 -0500
Subject: [PATCH] ssb: Canceling loads, more mobile-friendly sidebar, and
respond to channel subscription changes.
---
apps/ssb.json | 2 +-
apps/ssb/tf-app.js | 11 +++++++++++
apps/ssb/tf-tab-news-feed.js | 10 +++++++++-
apps/ssb/tf-tab-news.js | 12 ++++--------
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/apps/ssb.json b/apps/ssb.json
index 24de7f3ce..95f9a0aa5 100644
--- a/apps/ssb.json
+++ b/apps/ssb.json
@@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "🐌",
- "previous": "&ksxKqT3Bkp0Z2zV2dQU4ttVZ1k16zdWoJVv6R7m5yAQ=.sha256"
+ "previous": "&NniJybtFHDaypdljDj1kbGIpwU8T5lX9m7+bA1YTu+M=.sha256"
}
diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js
index e6e67e898..ecc4f318d 100644
--- a/apps/ssb/tf-app.js
+++ b/apps/ssb/tf-app.js
@@ -68,7 +68,10 @@ class TfElement extends LitElement {
let ids = (await tfrpc.rpc.getIdentities()) || [];
this.whoami = whoami ?? (ids.length ? ids[0] : undefined);
this.ids = ids;
+ await this.load_channels();
+ }
+ async load_channels() {
let channels = await tfrpc.rpc.query(`
SELECT
content ->> 'channel' AS channel,
@@ -192,6 +195,14 @@ class TfElement extends LitElement {
`,
[JSON.stringify(this.following), id]
);
+ for (let message of messages) {
+ if (message.author == this.whoami) {
+ let content = JSON.parse(message.content);
+ if (content?.type == 'channel') {
+ this.load_channels();
+ }
+ }
+ }
if (messages && messages.length) {
this.unread = [...this.unread, ...messages];
this.unread = this.unread.slice(this.unread.length - 1024);
diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js
index d93d1e062..64be2884b 100644
--- a/apps/ssb/tf-tab-news-feed.js
+++ b/apps/ssb/tf-tab-news-feed.js
@@ -146,9 +146,10 @@ class TfTabNewsFeedElement extends LitElement {
async load_more() {
this.loading++;
+ this.loading_canceled = false;
try {
let more = [];
- while (!more.length) {
+ while (!more.length && !this.loading_canceled) {
let last_start_time = this.start_time;
this.start_time = last_start_time - 7 * 24 * 60 * 60 * 1000;
more = await this.fetch_messages(this.start_time, last_start_time);
@@ -160,6 +161,10 @@ class TfTabNewsFeedElement extends LitElement {
}
}
+ cancel_load() {
+ this.loading_canceled = true;
+ }
+
async decrypt(messages) {
console.log('decrypt');
let result = [];
@@ -254,6 +259,9 @@ class TfTabNewsFeedElement extends LitElement {
+
Showing ${new Date(this.time_range[0]).toLocaleDateString()} - ${new Date(this.time_range[1]).toLocaleDateString()}.
`;
diff --git a/apps/ssb/tf-tab-news.js b/apps/ssb/tf-tab-news.js
index 22b109d0a..e41431a85 100644
--- a/apps/ssb/tf-tab-news.js
+++ b/apps/ssb/tf-tab-news.js
@@ -122,14 +122,10 @@ class TfTabNewsElement extends LitElement {
show_sidebar() {
this.renderRoot.getElementById('sidebar').style.display = 'block';
- this.renderRoot.getElementById('main').style.marginLeft = '2in';
- this.renderRoot.getElementById('show_sidebar').style.display = 'none';
}
hide_sidebar() {
this.renderRoot.getElementById('sidebar').style.display = 'none';
- this.renderRoot.getElementById('main').style.marginLeft = '0';
- this.renderRoot.getElementById('show_sidebar').style.display = 'block';
}
async channel_toggle_subscribed() {
@@ -176,8 +172,8 @@ class TfTabNewsElement extends LitElement {
`;
}
return html`
-