diff --git a/apps/ssb.json b/apps/ssb.json
index 0f3468e7..8808de71 100644
--- a/apps/ssb.json
+++ b/apps/ssb.json
@@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "π¦",
- "previous": "&TTGzyovmfKozjELCGPBFLLEXQcpfaArOMmqzemvz9J8=.sha256"
+ "previous": "&lFyDLIdToivp5zCqHBCRRBs3ESnWoKRi9JQJEkuclQ4=.sha256"
}
diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js
index d40866c5..7b08d568 100644
--- a/apps/ssb/tf-app.js
+++ b/apps/ssb/tf-app.js
@@ -22,6 +22,7 @@ class TfElement extends LitElement {
guest: {type: Boolean},
url: {type: String},
private_messages: {type: Array},
+ grouped_private_messages: {type: Object},
recent_reactions: {type: Array},
is_administrator: {type: Boolean},
stay_connected: {type: Boolean},
@@ -366,6 +367,32 @@ class TfElement extends LitElement {
return result;
}
+ async group_private_messages(messages) {
+ let groups = {};
+ let result = await this.decrypt(
+ await tfrpc.rpc.query(
+ `
+ SELECT messages.id, author, timestamp, json(content) AS content
+ FROM messages
+ JOIN json_each(?) AS ids
+ WHERE messages.id = ids.value
+ ORDER BY timestamp DESC
+ `,
+ [JSON.stringify(messages)]
+ )
+ );
+ for (let message of result) {
+ let key = JSON.stringify(
+ message?.decrypted?.recps?.filter((x) => x != this.whoami)?.sort()
+ );
+ if (!groups[key]) {
+ groups[key] = [];
+ }
+ groups[key].push(message);
+ }
+ return groups;
+ }
+
async load_channels_latest(following) {
let start_time = new Date();
let latest_private = this.get_latest_private(following);
@@ -438,12 +465,15 @@ class TfElement extends LitElement {
console.log('channels took', (new Date() - start_time) / 1000.0);
let self = this;
start_time = new Date();
- latest_private.then(function (latest) {
+ latest_private.then(async function (latest) {
self.channels_latest = Object.assign({}, self.channels_latest, {
'π': latest[0],
});
console.log('private took', (new Date() - start_time) / 1000.0);
self.private_messages = latest[1];
+ self.grouped_private_messages = await self.group_private_messages(
+ latest[1]
+ );
});
}
@@ -630,6 +660,7 @@ class TfElement extends LitElement {
@loadmessages=${this.reset_progress}
.connections=${this.connections}
.private_messages=${this.private_messages}
+ .grouped_private_messages=${this.grouped_private_messages}
.recent_reactions=${this.recent_reactions}
?is_administrator=${this.is_administrator}
?stay_connected=${this.stay_connected}
diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js
index ba8c1c0a..5bc3f590 100644
--- a/apps/ssb/tf-tab-news-feed.js
+++ b/apps/ssb/tf-tab-news-feed.js
@@ -18,6 +18,7 @@ class TfTabNewsFeedElement extends LitElement {
time_range: {type: Array},
time_loading: {type: Array},
private_messages: {type: Array},
+ grouped_private_messages: {type: Object},
recent_reactions: {type: Array},
};
}
@@ -227,6 +228,31 @@ class TfTabNewsFeedElement extends LitElement {
]
);
result = (await this.decrypt(result)).filter((x) => x.decrypted);
+ } else if (this.hash.startsWith('#π')) {
+ let ids = this.hash.substring('#π'.length).split(',');
+ console.log(this.grouped_private_messages);
+ result = await tfrpc.rpc.query(
+ `
+ SELECT TRUE AS is_primary, messages.rowid, messages.id, previous, author, sequence, timestamp, hash, json(content) AS content, signature
+ FROM messages
+ JOIN json_each(?1) AS private_messages ON messages.id = private_messages.value
+ WHERE
+ (?2 IS NULL OR (messages.timestamp >= ?2)) AND messages.timestamp < ?3 AND
+ json(messages.content) LIKE '"%'
+ ORDER BY messages.rowid DESC LIMIT ?4
+ `,
+ [
+ JSON.stringify(
+ this.grouped_private_messages?.[JSON.stringify(ids)]?.map(
+ (x) => x.id
+ ) ?? []
+ ),
+ start_time,
+ end_time,
+ k_max_results,
+ ]
+ );
+ result = (await this.decrypt(result)).filter((x) => x.decrypted);
} else if (this.hash == '#π') {
result = await tfrpc.rpc.query(
`
diff --git a/apps/ssb/tf-tab-news.js b/apps/ssb/tf-tab-news.js
index 87b095e1..efd156a0 100644
--- a/apps/ssb/tf-tab-news.js
+++ b/apps/ssb/tf-tab-news.js
@@ -24,6 +24,7 @@ class TfTabNewsElement extends LitElement {
channels_latest: {type: Object},
connections: {type: Array},
private_messages: {type: Array},
+ grouped_private_messages: {type: Object},
recent_reactions: {type: Array},
peer_exchange: {type: Boolean},
is_administrator: {type: Boolean},
@@ -257,12 +258,26 @@ class TfTabNewsElement extends LitElement {
style=${this.hash == '#π' ? 'font-weight: bold' : undefined}
>${this.unread_status('π')}πvotes
- ${this.unread_status('π')}πprivate
+ ${Object.keys(this?.grouped_private_messages ?? [])?.map(
+ (key) => html`
+ ${(key != '[]' ? JSON.parse(key) : [this.whoami]).map(
+ (id) => html`
+