ssb: Use most recent post timestamps to feature more relevant people to follow.
This commit is contained in:
parent
e198ff9cb1
commit
db0a4bff77
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🦀",
|
||||
"previous": "&ywgXrIlVu5chLPseAwTXdpzaxGep+rjs1ZPeV4tj3wM=.sha256"
|
||||
"previous": "&IbDnKRKxIZzdIhs2wVVdNt560YlLuM/8coMuTuJhVNs=.sha256"
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ class TfElement extends LitElement {
|
||||
let max_row_id = (
|
||||
await tfrpc.rpc.query(
|
||||
`
|
||||
SELECT MAX(rowid) AS max_row_id FROM messages
|
||||
`,
|
||||
SELECT MAX(rowid) AS max_row_id FROM messages
|
||||
`,
|
||||
[]
|
||||
)
|
||||
)[0].max_row_id;
|
||||
@ -177,7 +177,7 @@ class TfElement extends LitElement {
|
||||
let abouts = await tfrpc.rpc.query(
|
||||
`
|
||||
SELECT
|
||||
messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
|
||||
messages.author, json(messages.content) AS content, messages.sequence
|
||||
FROM
|
||||
messages,
|
||||
json_each(?1) AS following
|
||||
@ -188,7 +188,7 @@ class TfElement extends LitElement {
|
||||
json_extract(messages.content, '$.type') = 'about'
|
||||
UNION
|
||||
SELECT
|
||||
messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
|
||||
messages.author, json(messages.content) AS content, messages.sequence
|
||||
FROM
|
||||
messages,
|
||||
json_each(?2) AS following
|
||||
@ -383,10 +383,9 @@ class TfElement extends LitElement {
|
||||
this.channels_latest = Object.fromEntries(
|
||||
channels.map((x) => [x.channel, x.rowid])
|
||||
);
|
||||
console.log('latest', this.channels_latest);
|
||||
console.log('unread', this.channels_unread);
|
||||
console.log('channels took', (new Date() - start_time) / 1000.0);
|
||||
let self = this;
|
||||
start_time = new Date();
|
||||
latest_private.then(function (latest) {
|
||||
self.channels_latest = Object.assign({}, self.channels_latest, {
|
||||
'🔐': latest,
|
||||
@ -410,6 +409,24 @@ class TfElement extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
async fetch_user_info(users) {
|
||||
let info = await tfrpc.rpc.query(
|
||||
`
|
||||
SELECT messages.author, MAX(messages.sequence) AS max_seq, MAX(timestamp) AS max_ts FROM messages
|
||||
JOIN json_each(?) AS following
|
||||
ON messages.author = following.value
|
||||
GROUP BY messages.author
|
||||
`,
|
||||
[
|
||||
JSON.stringify(Object.keys(users)),
|
||||
]);
|
||||
for (let row of info) {
|
||||
users[row.author].seq = row.max_seq;
|
||||
users[row.author].ts = row.max_ts;
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
async load() {
|
||||
this.loading_latest = true;
|
||||
try {
|
||||
@ -440,6 +457,9 @@ class TfElement extends LitElement {
|
||||
Object.keys(users).length,
|
||||
'users'
|
||||
);
|
||||
start_time = new Date();
|
||||
users = await this.fetch_user_info(users);
|
||||
console.log('user info took', (new Date() - start_time) / 1000.0, 'seconds');
|
||||
this.users = users;
|
||||
console.log(
|
||||
`load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}`
|
||||
@ -573,8 +593,7 @@ class TfElement extends LitElement {
|
||||
style="position: static; top: 0; z-index: 10"
|
||||
>
|
||||
<button
|
||||
class=${'w3-bar-item w3-button w3-circle w3-ripple' +
|
||||
(this.connections?.some((x) => x.flags.one_shot) ? ' w3-spin' : '')}
|
||||
class=${'w3-bar-item w3-button w3-circle w3-ripple' + (this.connections?.some(x => x.flags.one_shot) ? ' w3-spin' : '')}
|
||||
@click=${this.refresh}
|
||||
>
|
||||
↻
|
||||
|
@ -275,8 +275,8 @@ class TfTabNewsFeedElement extends LitElement {
|
||||
}
|
||||
|
||||
merge_messages(old_messages, new_messages) {
|
||||
let old_by_id = Object.fromEntries(old_messages.map((x) => [x.id, x]));
|
||||
return new_messages.map((x) => (old_by_id[x.id] ? old_by_id[x.id] : x));
|
||||
let old_by_id = Object.fromEntries(old_messages.map(x => [x.id, x]));
|
||||
return new_messages.map(x => old_by_id[x.id] ? old_by_id[x.id] : x);
|
||||
}
|
||||
|
||||
async load_latest() {
|
||||
@ -298,17 +298,14 @@ class TfTabNewsFeedElement extends LitElement {
|
||||
} finally {
|
||||
this.loading--;
|
||||
}
|
||||
this.messages = this.merge_messages(
|
||||
this.messages,
|
||||
Object.values(
|
||||
Object.fromEntries(
|
||||
[...this.messages, ...messages]
|
||||
.sort((x, y) => x.timestamp - y.timestamp)
|
||||
.slice(-1024)
|
||||
.map((x) => [x.id, x])
|
||||
)
|
||||
this.messages = this.merge_messages(this.messages, Object.values(
|
||||
Object.fromEntries(
|
||||
[...this.messages, ...messages]
|
||||
.sort((x, y) => x.timestamp - y.timestamp)
|
||||
.slice(-1024)
|
||||
.map((x) => [x.id, x])
|
||||
)
|
||||
);
|
||||
));
|
||||
console.log('done loading latest messages.');
|
||||
}
|
||||
|
||||
|
@ -128,21 +128,24 @@ class TfTabNewsElement extends LitElement {
|
||||
return this.hash.startsWith('##') ? this.hash.substring(2) : undefined;
|
||||
}
|
||||
|
||||
compare_follows(a, b) {
|
||||
return a[1].followed - b[1].followed;
|
||||
compare_follows() {
|
||||
const now = new Date().valueOf();
|
||||
return function (a, b) {
|
||||
return (b[1].ts > now ? -1 : b[1].ts) - (a[1].ts > now ? -1 : a[1].ts);
|
||||
};
|
||||
}
|
||||
|
||||
suggested_follows() {
|
||||
/*
|
||||
** Filter out people who have used future timestamps so that they aren't
|
||||
** pinned at the top.
|
||||
*/
|
||||
let self = this;
|
||||
return Object.entries(this.users).filter(
|
||||
(x) => (x[1].follow_depth > 1)
|
||||
).sort(
|
||||
self.compare_follows
|
||||
).slice(
|
||||
0, 8
|
||||
).map(
|
||||
(x) => (x[0])
|
||||
);
|
||||
return Object.entries(this.users)
|
||||
.filter((x) => x[1].follow_depth > 1)
|
||||
.sort(self.compare_follows())
|
||||
.slice(0, 8)
|
||||
.map((x) => x[0]);
|
||||
}
|
||||
|
||||
render_sidebar() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user