From d8a471272ddbf57072c35ebb7ff082793cdaa9cd Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Sun, 7 Apr 2024 20:37:54 -0300 Subject: [PATCH] feat: update home timeline in realtime when reposting --- src/controllers/api/streaming.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index c864962e..05eaf205 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -5,7 +5,7 @@ import { Debug, z } from '@/deps.ts'; import { getFeedPubkeys } from '@/queries.ts'; import { Sub } from '@/subs.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'); @@ -63,6 +63,13 @@ const streamingController: AppController = (c) => { if (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); if (status) { send('update', status); @@ -87,20 +94,20 @@ async function topicToFilter( switch (topic) { case 'public': - return { kinds: [1] }; + return { kinds: [1, 6] }; case 'public:local': - return { kinds: [1], search: `domain:${host}` }; + return { kinds: [1, 6], search: `domain:${host}` }; case 'hashtag': - if (query.tag) return { kinds: [1], '#t': [query.tag] }; + if (query.tag) return { kinds: [1, 6], '#t': [query.tag] }; break; 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; case 'user': // HACK: this puts the user's entire contacts list into RAM, // and then calls `matchFilters` over it. Refreshing the page // 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; } }