From 9d2667679fdac0adc956b4927ddd8417e4f08500 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 13 Sep 2024 10:28:54 -0300 Subject: [PATCH] feat(pipeline.ts): create handleAuthorSearch() function --- src/pipeline.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pipeline.ts b/src/pipeline.ts index 88e5f29b..9d1a8038 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -57,6 +57,7 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise, event: NostrEvent) { } } +async function handleAuthorSearch(kysely: Kysely, event: NostrEvent) { + if (event.kind !== 0) return; + const { name, nip05 } = n.json().pipe(n.metadata()).catch({}).parse(event.content); + const search = [name, nip05].filter(Boolean).join(' ').trim(); + + try { + await kysely.insertInto('author_search').values({ + pubkey: event.pubkey, + search, + }).onConflict( + (oc) => + oc.column('pubkey') + .doUpdateSet({ search }), + ) + .execute(); + } catch { + // do nothing + } +} + export { handleEvent, handleZaps };