Merge branch 'fix-block-not-working-in-streaming' into 'main'

Don't show posts from blocked users (fix streaming)

Closes #95

See merge request soapbox-pub/ditto!200
This commit is contained in:
Alex Gleason 2024-05-01 01:03:49 +00:00
commit 51d7bf4438
4 changed files with 20 additions and 9 deletions

View File

@ -8,8 +8,9 @@ import { getFeedPubkeys } from '@/queries.ts';
import { bech32ToPubkey } from '@/utils.ts'; import { bech32ToPubkey } from '@/utils.ts';
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts'; import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
import { hydrateEvents } from '@/storages/hydrate.ts'; import { hydrateEvents } from '@/storages/hydrate.ts';
import { eventsDB } from '@/storages.ts';
import { Storages } 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'); const debug = Debug('ditto:streaming');
@ -71,9 +72,14 @@ const streamingController: AppController = (c) => {
try { try {
for await (const msg of Storages.pubsub.req([filter], { signal: controller.signal })) { for await (const msg of Storages.pubsub.req([filter], { signal: controller.signal })) {
if (msg[0] === 'EVENT') { if (msg[0] === 'EVENT') {
const [event] = await hydrateEvents({ const store = new UserStore(pubkey as string, getAdminStore());
events: [msg[2]],
storage: eventsDB, const [event] = await store.query([{ ids: [msg[2].id] }]);
if (!event) continue;
await hydrateEvents({
events: [event],
storage: store,
signal: AbortSignal.timeout(1000), signal: AbortSignal.timeout(1000),
}); });

View File

@ -1,13 +1,11 @@
import { AppMiddleware } from '@/app.ts'; import { AppMiddleware } from '@/app.ts';
import { Conf } from '@/config.ts';
import { UserStore } from '@/storages/UserStore.ts'; import { UserStore } from '@/storages/UserStore.ts';
import { eventsDB } from '@/storages.ts'; import { getAdminStore } from '@/storages/adminStore.ts';
/** Store middleware. */ /** Store middleware. */
const storeMiddleware: AppMiddleware = async (c, next) => { const storeMiddleware: AppMiddleware = async (c, next) => {
const pubkey = c.get('pubkey'); const pubkey = c.get('pubkey');
const adminStore = new UserStore(Conf.pubkey, eventsDB); const adminStore = getAdminStore();
if (pubkey) { if (pubkey) {
const store = new UserStore(pubkey, adminStore); const store = new UserStore(pubkey, adminStore);
c.set('store', store); c.set('store', store);

View File

@ -29,7 +29,7 @@ export class UserStore implements NStore {
const mutedPubkeys = getTagSet(mutedPubkeysEvent.tags, 'p'); const mutedPubkeys = getTagSet(mutedPubkeysEvent.tags, 'p');
return allEvents.filter((event) => { return allEvents.filter((event) => {
return mutedPubkeys.has(event.pubkey) === false; return event.kind === 0 || mutedPubkeys.has(event.pubkey) === false;
}); });
} }

View File

@ -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);
}