ssb: Add a button to close a private chat, removing it from the sidebar.

This commit is contained in:
2025-08-20 19:08:07 -04:00
parent 910c39cbd0
commit 18e5b41663
3 changed files with 69 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🦀", "emoji": "🦀",
"previous": "&TAWjrbigDwIVPfpx1I/MAUBMO+szgKW8TX7orlyCA0g=.sha256" "previous": "&Jzy85+s6mwG7/Yk1sv7jDIrVaGU2NDnRkT1LMEEtRyM=.sha256"
} }

View File

@@ -21,6 +21,7 @@ class TfElement extends LitElement {
channels_latest: {type: Object}, channels_latest: {type: Object},
guest: {type: Boolean}, guest: {type: Boolean},
url: {type: String}, url: {type: String},
private_closed: {type: Object},
private_messages: {type: Array}, private_messages: {type: Array},
grouped_private_messages: {type: Object}, grouped_private_messages: {type: Object},
recent_reactions: {type: Array}, recent_reactions: {type: Array},
@@ -49,6 +50,7 @@ class TfElement extends LitElement {
this.loading_latest = 0; this.loading_latest = 0;
this.loading_latest_scheduled = 0; this.loading_latest_scheduled = 0;
this.recent_reactions = []; this.recent_reactions = [];
this.private_closed = {};
tfrpc.rpc.getBroadcasts().then((b) => { tfrpc.rpc.getBroadcasts().then((b) => {
self.broadcasts = b || []; self.broadcasts = b || [];
}); });
@@ -86,9 +88,23 @@ class TfElement extends LitElement {
this.whoami = whoami ?? (ids.length ? ids[0] : undefined); this.whoami = whoami ?? (ids.length ? ids[0] : undefined);
this.guest = !this.whoami?.length; this.guest = !this.whoami?.length;
this.ids = ids; this.ids = ids;
let private_closed =
(await tfrpc.rpc.databaseGet('private_closed')) ?? '{}';
this.private_closed = JSON.parse(private_closed);
await this.load_channels(); await this.load_channels();
} }
async close_private_chat(event) {
let update = {};
update[event.detail.key] = true;
this.private_closed = Object.assign(update, this.private_closed);
console.log(this.private_closed);
await tfrpc.rpc.databaseSet(
'private_closed',
JSON.stringify(this.private_closed)
);
}
async load_channels() { async load_channels() {
let channels = await tfrpc.rpc.query( let channels = await tfrpc.rpc.query(
` `
@@ -136,12 +152,30 @@ class TfElement extends LitElement {
} }
} }
visible_private() {
if (!this.grouped_private_messages || !this.private_closed) {
return [];
}
let self = this;
return Object.fromEntries(
Object.entries(this.grouped_private_messages).filter(([key, value]) => {
let channel = '🔐' + [...new Set(JSON.parse(key))].sort().join(',');
let grouped_latest = Math.max(...value.map((x) => x.rowid));
return (
!self.private_closed[key] ||
self.channels_unread[channel] === undefined ||
grouped_latest > self.channels_unread[channel]
);
})
);
}
next_channel(delta) { next_channel(delta) {
let channel_names = [ let channel_names = [
'', '',
'@', '@',
'👍', '👍',
...Object.keys(this.grouped_private_messages) ...Object.keys(this.visible_private())
.sort() .sort()
.map((x) => '🔐' + JSON.parse(x).join(',')), .map((x) => '🔐' + JSON.parse(x).join(',')),
...this.channels.map((x) => '#' + x), ...this.channels.map((x) => '#' + x),
@@ -385,7 +419,11 @@ class TfElement extends LitElement {
); );
for (let message of result) { for (let message of result) {
let key = JSON.stringify( let key = JSON.stringify(
message?.decrypted?.recps?.filter((x) => x != this.whoami)?.sort() ?? [] [
...new Set(
message?.decrypted?.recps?.filter((x) => x != this.whoami)
),
].sort() ?? []
); );
if (!groups[key]) { if (!groups[key]) {
groups[key] = []; groups[key] = [];
@@ -660,9 +698,10 @@ class TfElement extends LitElement {
@refresh=${this.refresh} @refresh=${this.refresh}
@toggle_stay_connected=${this.toggle_stay_connected} @toggle_stay_connected=${this.toggle_stay_connected}
@loadmessages=${this.reset_progress} @loadmessages=${this.reset_progress}
@closeprivatechat=${this.close_private_chat}
.connections=${this.connections} .connections=${this.connections}
.private_messages=${this.private_messages} .private_messages=${this.private_messages}
.grouped_private_messages=${this.grouped_private_messages} .grouped_private_messages=${this.visible_private()}
.recent_reactions=${this.recent_reactions} .recent_reactions=${this.recent_reactions}
?is_administrator=${this.is_administrator} ?is_administrator=${this.is_administrator}
?stay_connected=${this.stay_connected} ?stay_connected=${this.stay_connected}

View File

@@ -433,6 +433,31 @@ class TfTabNewsFeedElement extends LitElement {
} }
} }
close_private_chat() {
this.mark_all_read();
this.dispatchEvent(
new CustomEvent('closeprivatechat', {
bubbles: true,
composed: true,
detail: {
key: JSON.stringify(this.hash.substring('#🔐'.length).split(',')),
},
})
);
}
render_close_chat_button() {
if (this.hash.startsWith('#🔐')) {
return html`
<button class="w3-button w3-theme-d1" @click=${this.close_private_chat}>
Close Chat
</button>
`;
} else {
return html`${this.hash}`;
}
}
render() { render() {
if ( if (
!this.messages || !this.messages ||
@@ -500,6 +525,7 @@ class TfTabNewsFeedElement extends LitElement {
Mark All Read Mark All Read
</button>` </button>`
: undefined} : undefined}
${this.render_close_chat_button()}
<tf-news <tf-news
id="news" id="news"
whoami=${this.whoami} whoami=${this.whoami}