From 45e1762b5006859f998d5739d12a5440e9cc158d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 12 Mar 2024 16:10:19 -0500 Subject: [PATCH] pipeline: handle registrations --- src/pipeline.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index ead0044..730e333 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -37,6 +37,7 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise { + if (event.kind !== 5951) return; + const signer = new AdminSigner(); + + const exists = (await eventsDB.count( + [{ kinds: [30361], authors: [Conf.pubkey], '#d': [event.pubkey], limit: 1 }], + )).count > 0; + + if (exists) { + const feedback = await signer.signEvent({ + kind: 7000, + content: '', + tags: [ + ['status', 'error', 'User already exists'], + ['e', event.id], + ['p', event.pubkey], + ], + created_at: nostrNow(), + }); + return handleEvent(feedback, AbortSignal.timeout(1000)); + } + + const user = await signer.signEvent({ + kind: 30361, + tags: [ + ['d', event.pubkey], + ], + content: '', + created_at: nostrNow(), + }); + + const resp = await signer.signEvent({ + kind: 6951, + content: Conf.relay, + tags: [ + ['request', JSON.stringify(event)], + ['i', Conf.relay, 'text'], + ['p', event.pubkey], + ['e', event.id], + ], + created_at: nostrNow(), + }); + + await Promise.all([ + handleEvent(user, AbortSignal.timeout(1000)), + handleEvent(resp, AbortSignal.timeout(1000)), + ]); +} + /** Emit Nostr Wallet Connect event from zaps so users may pay. */ async function payZap(event: DittoEvent, signal: AbortSignal) { if (event.kind !== 9734 || !event.user) return;