From 48195f02b3fcb27d486f2b8427f41495be82f63a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 5 Sep 2023 20:29:35 -0500 Subject: [PATCH] pipeline: don't store event if a deletion for it exists --- src/pipeline.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index c1974d6..1bbed40 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -4,6 +4,7 @@ import { addRelays } from '@/db/relays.ts'; import { findUser } from '@/db/users.ts'; import { type Event, LRUCache } from '@/deps.ts'; import { isEphemeralKind } from '@/kinds.ts'; +import * as mixer from '@/mixer.ts'; import { isLocallyFollowed } from '@/queries.ts'; import { Sub } from '@/subs.ts'; import { trends } from '@/trends.ts'; @@ -49,8 +50,18 @@ const isAdminEvent = ({ pubkey }: Event): boolean => pubkey === Conf.pubkey; /** Maybe store the event, if eligible. */ async function storeEvent(event: Event, data: EventData): Promise { if (isEphemeralKind(event.kind)) return; + if (data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) { - await eventsDB.insertEvent(event).catch(console.warn); + const [deletion] = await mixer.getFilters( + [{ kinds: [5], authors: [event.pubkey], '#e': [event.id], limit: 1 }], + { limit: 1, timeout: Time.seconds(1) }, + ); + + if (deletion) { + return Promise.reject(new RelayError('blocked', 'event was deleted')); + } else { + await eventsDB.insertEvent(event).catch(console.warn); + } } else { return Promise.reject(new RelayError('blocked', 'only registered users can post')); }