Compare commits

..

No commits in common. "f7602b39a1d4a90ac8cce5122bd0b557a0856a63" and "e198ff9cb11cbfddd2bb2aa5272be30b95bc477a" have entirely different histories.

5 changed files with 33 additions and 53 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🦀", "emoji": "🦀",
"previous": "&2ZH/mtbvbK35gpBMgZ5CjklFEbjWAcpr1fbVvCQma9E=.sha256" "previous": "&ywgXrIlVu5chLPseAwTXdpzaxGep+rjs1ZPeV4tj3wM=.sha256"
} }

View File

@ -177,7 +177,7 @@ class TfElement extends LitElement {
let abouts = await tfrpc.rpc.query( let abouts = await tfrpc.rpc.query(
` `
SELECT SELECT
messages.author, json(messages.content) AS content, messages.sequence messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
FROM FROM
messages, messages,
json_each(?1) AS following json_each(?1) AS following
@ -188,7 +188,7 @@ class TfElement extends LitElement {
json_extract(messages.content, '$.type') = 'about' json_extract(messages.content, '$.type') = 'about'
UNION UNION
SELECT SELECT
messages.author, json(messages.content) AS content, messages.sequence messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
FROM FROM
messages, messages,
json_each(?2) AS following json_each(?2) AS following
@ -383,9 +383,10 @@ class TfElement extends LitElement {
this.channels_latest = Object.fromEntries( this.channels_latest = Object.fromEntries(
channels.map((x) => [x.channel, x.rowid]) 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); console.log('channels took', (new Date() - start_time) / 1000.0);
let self = this; let self = this;
start_time = new Date();
latest_private.then(function (latest) { latest_private.then(function (latest) {
self.channels_latest = Object.assign({}, self.channels_latest, { self.channels_latest = Object.assign({}, self.channels_latest, {
'🔐': latest, '🔐': latest,
@ -409,24 +410,6 @@ 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() { async load() {
this.loading_latest = true; this.loading_latest = true;
try { try {
@ -457,9 +440,6 @@ class TfElement extends LitElement {
Object.keys(users).length, Object.keys(users).length,
'users' '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; this.users = users;
console.log( console.log(
`load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}` `load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}`
@ -593,8 +573,8 @@ class TfElement extends LitElement {
style="position: static; top: 0; z-index: 10" style="position: static; top: 0; z-index: 10"
> >
<button <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' +
style="width: 1.5em; height: 1.5em; padding: 8px" (this.connections?.some((x) => x.flags.one_shot) ? ' w3-spin' : '')}
@click=${this.refresh} @click=${this.refresh}
> >

View File

@ -594,7 +594,7 @@ class TfComposeElement extends LitElement {
.innerText=${live(draft.text ?? '')} .innerText=${live(draft.text ?? '')}
></span> ></span>
</div> </div>
<div class="w3-half w3-container"> <div class="w3-half">
${content_warning} ${content_warning}
<p id="preview"></p> <p id="preview"></p>
</div> </div>

View File

@ -275,8 +275,8 @@ class TfTabNewsFeedElement extends LitElement {
} }
merge_messages(old_messages, new_messages) { merge_messages(old_messages, new_messages) {
let old_by_id = Object.fromEntries(old_messages.map(x => [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); return new_messages.map((x) => (old_by_id[x.id] ? old_by_id[x.id] : x));
} }
async load_latest() { async load_latest() {
@ -298,14 +298,17 @@ class TfTabNewsFeedElement extends LitElement {
} finally { } finally {
this.loading--; this.loading--;
} }
this.messages = this.merge_messages(this.messages, Object.values( this.messages = this.merge_messages(
this.messages,
Object.values(
Object.fromEntries( Object.fromEntries(
[...this.messages, ...messages] [...this.messages, ...messages]
.sort((x, y) => x.timestamp - y.timestamp) .sort((x, y) => x.timestamp - y.timestamp)
.slice(-1024) .slice(-1024)
.map((x) => [x.id, x]) .map((x) => [x.id, x])
) )
)); )
);
console.log('done loading latest messages.'); console.log('done loading latest messages.');
} }

View File

@ -128,24 +128,21 @@ class TfTabNewsElement extends LitElement {
return this.hash.startsWith('##') ? this.hash.substring(2) : undefined; return this.hash.startsWith('##') ? this.hash.substring(2) : undefined;
} }
compare_follows() { compare_follows(a, b) {
const now = new Date().valueOf(); return a[1].followed - b[1].followed;
return function (a, b) {
return (b[1].ts > now ? -1 : b[1].ts) - (a[1].ts > now ? -1 : a[1].ts);
};
} }
suggested_follows() { suggested_follows() {
/*
** Filter out people who have used future timestamps so that they aren't
** pinned at the top.
*/
let self = this; let self = this;
return Object.entries(this.users) return Object.entries(this.users).filter(
.filter((x) => x[1].follow_depth > 1) (x) => (x[1].follow_depth > 1)
.sort(self.compare_follows()) ).sort(
.slice(0, 8) self.compare_follows
.map((x) => x[0]); ).slice(
0, 8
).map(
(x) => (x[0])
);
} }
render_sidebar() { render_sidebar() {