feat: update home timeline in realtime when reposting

This commit is contained in:
P. Reis 2024-04-07 20:37:54 -03:00
parent 25b1e7229c
commit d8a471272d
1 changed files with 13 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import { Debug, z } from '@/deps.ts';
import { getFeedPubkeys } from '@/queries.ts'; import { getFeedPubkeys } from '@/queries.ts';
import { Sub } from '@/subs.ts'; import { Sub } from '@/subs.ts';
import { bech32ToPubkey } from '@/utils.ts'; import { bech32ToPubkey } from '@/utils.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts'; import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
const debug = Debug('ditto:streaming'); const debug = Debug('ditto:streaming');
@ -63,6 +63,13 @@ const streamingController: AppController = (c) => {
if (filter) { if (filter) {
for await (const event of Sub.sub(socket, '1', [filter])) { for await (const event of Sub.sub(socket, '1', [filter])) {
if (event.kind == 6) {
const status = await renderReblog(event);
if (status) {
send('update', status);
}
return;
}
const status = await renderStatus(event, pubkey); const status = await renderStatus(event, pubkey);
if (status) { if (status) {
send('update', status); send('update', status);
@ -87,20 +94,20 @@ async function topicToFilter(
switch (topic) { switch (topic) {
case 'public': case 'public':
return { kinds: [1] }; return { kinds: [1, 6] };
case 'public:local': case 'public:local':
return { kinds: [1], search: `domain:${host}` }; return { kinds: [1, 6], search: `domain:${host}` };
case 'hashtag': case 'hashtag':
if (query.tag) return { kinds: [1], '#t': [query.tag] }; if (query.tag) return { kinds: [1, 6], '#t': [query.tag] };
break; break;
case 'hashtag:local': case 'hashtag:local':
if (query.tag) return { kinds: [1], '#t': [query.tag], search: `domain:${host}` }; if (query.tag) return { kinds: [1, 6], '#t': [query.tag], search: `domain:${host}` };
break; break;
case 'user': case 'user':
// HACK: this puts the user's entire contacts list into RAM, // HACK: this puts the user's entire contacts list into RAM,
// and then calls `matchFilters` over it. Refreshing the page // and then calls `matchFilters` over it. Refreshing the page
// is required after following a new user. // is required after following a new user.
return pubkey ? { kinds: [1], authors: await getFeedPubkeys(pubkey) } : undefined; return pubkey ? { kinds: [1, 6], authors: await getFeedPubkeys(pubkey) } : undefined;
} }
} }