From b1d68ac307ed87d63e83820cbdf843fff0fd9f7f Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 11 Sep 2025 01:48:14 +0700 Subject: init --- front/src/logic/nostril.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 front/src/logic/nostril.ts (limited to 'front/src/logic/nostril.ts') diff --git a/front/src/logic/nostril.ts b/front/src/logic/nostril.ts new file mode 100644 index 0000000..4e5549d --- /dev/null +++ b/front/src/logic/nostril.ts @@ -0,0 +1,36 @@ +import type { Event } from "@/types/nostr"; +import type { FC, FlatFeed, Poast } from "@/types/trill"; +import { engagementBunt, openLock } from "./bunts"; +export function eventsToFc(relayData: Record): FC { + const start = null; + const end = null; + const feed = Object.values(relayData).reduce((acc: FlatFeed, events) => { + const poasts = events.map(eventToPoast); + for (const p of poasts) { + if (p) acc[p.id] = p; + } + return acc; + }, {}); + return { feed, start, end }; +} +export function eventToPoast(event: Event): Poast | null { + if (event.kind !== 1) return null; + const contents = [{ paragraph: [{ text: event.content }] }]; + const ts = event.created_at * 1000; + const id = `${ts}`; + const poast: Poast = { + id, + host: event.pubkey, + author: event.pubkey, + contents, + thread: id, + parent: null, + read: openLock, + write: openLock, + tags: [], + time: ts, + engagement: engagementBunt, + children: [], + }; + return poast; +} -- cgit v1.2.3