diff options
Diffstat (limited to 'front/src/logic/nostril.ts')
-rw-r--r-- | front/src/logic/nostril.ts | 36 |
1 files changed, 36 insertions, 0 deletions
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<string, Event[]>): 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; +} |