parse.ts (770B)
1 import { KIND_REACTION, type RadrootsReaction } from "@radroots/events-bindings"; 2 import type { NostrEvent } from "../../types/nostr.js"; 3 import { parse_nostr_event_basis } from "../lib.js"; 4 import type { NostrEventBasis } from "../subscription.js"; 5 6 export type RadrootsReactionNostrEvent = NostrEventBasis<typeof KIND_REACTION> & { reaction: RadrootsReaction }; 7 8 export const parse_nostr_reaction_event = ( 9 event: NostrEvent, 10 ): RadrootsReactionNostrEvent | undefined => { 11 const ev = parse_nostr_event_basis(event, KIND_REACTION); 12 if (!ev) return undefined; 13 try { 14 const parsed = JSON.parse(event.content); 15 const reaction = parsed as RadrootsReaction; 16 return { ...ev, reaction }; 17 } catch { 18 return undefined; 19 } 20 };