summaryrefslogtreecommitdiff
path: root/front/src/logic/nostril.ts
blob: 4e5549df154d59ef73efb43f307a8be6e3a711fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
}