diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index 668218d..c190c3e 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -8,8 +8,9 @@ import { getFeedPubkeys } from '@/queries.ts'; import { bech32ToPubkey } from '@/utils.ts'; import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts'; import { hydrateEvents } from '@/storages/hydrate.ts'; -import { eventsDB } from '@/storages.ts'; import { Storages } from '@/storages.ts'; +import { UserStore } from '@/storages/UserStore.ts'; +import { getAdminStore } from '@/storages/adminStore.ts'; const debug = Debug('ditto:streaming'); @@ -71,9 +72,14 @@ const streamingController: AppController = (c) => { try { for await (const msg of Storages.pubsub.req([filter], { signal: controller.signal })) { if (msg[0] === 'EVENT') { - const [event] = await hydrateEvents({ - events: [msg[2]], - storage: eventsDB, + const store = new UserStore(pubkey as string, getAdminStore()); + + const [event] = await store.query([{ ids: [msg[2].id] }]); + if (!event) continue; + + await hydrateEvents({ + events: [event], + storage: store, signal: AbortSignal.timeout(1000), }); diff --git a/src/middleware/store.ts b/src/middleware/store.ts index 67bee0a..f0c417f 100644 --- a/src/middleware/store.ts +++ b/src/middleware/store.ts @@ -1,13 +1,11 @@ import { AppMiddleware } from '@/app.ts'; -import { Conf } from '@/config.ts'; import { UserStore } from '@/storages/UserStore.ts'; -import { eventsDB } from '@/storages.ts'; +import { getAdminStore } from '@/storages/adminStore.ts'; /** Store middleware. */ const storeMiddleware: AppMiddleware = async (c, next) => { const pubkey = c.get('pubkey'); - const adminStore = new UserStore(Conf.pubkey, eventsDB); - + const adminStore = getAdminStore(); if (pubkey) { const store = new UserStore(pubkey, adminStore); c.set('store', store); diff --git a/src/storages/UserStore.ts b/src/storages/UserStore.ts index 78c3d33..a3f0726 100644 --- a/src/storages/UserStore.ts +++ b/src/storages/UserStore.ts @@ -29,7 +29,7 @@ export class UserStore implements NStore { const mutedPubkeys = getTagSet(mutedPubkeysEvent.tags, 'p'); return allEvents.filter((event) => { - return mutedPubkeys.has(event.pubkey) === false; + return event.kind === 0 || mutedPubkeys.has(event.pubkey) === false; }); } diff --git a/src/storages/adminStore.ts b/src/storages/adminStore.ts new file mode 100644 index 0000000..0b5bb38 --- /dev/null +++ b/src/storages/adminStore.ts @@ -0,0 +1,7 @@ +import { UserStore } from '@/storages/UserStore.ts'; +import { Conf } from '@/config.ts'; +import { eventsDB } from '@/storages.ts'; + +export function getAdminStore() { + return new UserStore(Conf.pubkey, eventsDB); +}