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; }