From ba6d33c115fbbb6e1166eb18d893d78a363a4220 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 30 Apr 2024 21:20:19 -0300 Subject: [PATCH 1/4] feat: create getAdminStore() func --- src/storages/adminStore.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/storages/adminStore.ts 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); +} From e8e45360d32e2741f3c3ecbc810f79de6cfc1add Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 30 Apr 2024 21:21:32 -0300 Subject: [PATCH 2/4] refactor(store middleware): get adminStore through function --- src/middleware/store.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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); From f0c66c1e92c4c679bd6bdbd383dd1146f8b7b04f Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 30 Apr 2024 21:23:25 -0300 Subject: [PATCH 3/4] fix(streaming): don't show posts from blocked users --- src/controllers/api/streaming.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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), }); From de08aeac104c8bca5b93bf7b1b58d7cd8b71e695 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 30 Apr 2024 21:28:45 -0300 Subject: [PATCH 4/4] fix: allow to query kind 0 of blocked users --- src/storages/UserStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; }); }