diff --git a/src/pipeline.ts b/src/pipeline.ts index f59a1eb..7cdaa60 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -3,10 +3,12 @@ import Debug from '@soapbox/stickynotes/debug'; import { sql } from 'kysely'; import { LRUCache } from 'lru-cache'; +import { Conf } from '@/config.ts'; import { DittoDB } from '@/db/DittoDB.ts'; import { deleteAttachedMedia } from '@/db/unattached-media.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { RelayError } from '@/RelayError.ts'; +import { AdminSigner } from '@/signers/AdminSigner.ts'; import { hydrateEvents } from '@/storages/hydrate.ts'; import { Storages } from '@/storages.ts'; import { eventAge, parseNip05, Time } from '@/utils.ts'; @@ -53,6 +55,7 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise { } } +async function generateSetEvents(event: NostrEvent): Promise { + const tagsAdmin = event.tags.some(([name, value]) => ['p', 'P'].includes(name) && value === Conf.pubkey); + + if (event.kind === 1984 && tagsAdmin) { + const signer = new AdminSigner(); + + const rel = await signer.signEvent({ + kind: 30383, + content: '', + tags: [ + ['d', event.id], + ['p', event.pubkey], + ['k', '1984'], + ['n', 'open'], + ...[...getTagSet(event.tags, 'p')].map((pubkey) => ['P', pubkey]), + ...[...getTagSet(event.tags, 'e')].map((pubkey) => ['e', pubkey]), + ], + created_at: Math.floor(Date.now() / 1000), + }); + + await handleEvent(rel, AbortSignal.timeout(1000)); + } + + if (event.kind === 3036 && tagsAdmin) { + const signer = new AdminSigner(); + + const rel = await signer.signEvent({ + kind: 30383, + content: '', + tags: [ + ['d', event.id], + ['p', event.pubkey], + ['k', '3036'], + ['n', 'open'], + ], + created_at: Math.floor(Date.now() / 1000), + }); + + await handleEvent(rel, AbortSignal.timeout(1000)); + } +} + export { handleEvent };