diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index 6a92d80..e56ebe6 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -1,3 +1,4 @@ +import { Conf } from '@/config.ts'; import { db } from '@/db.ts'; import { type NostrEvent, type NStore } from '@/deps.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; @@ -29,6 +30,9 @@ async function hydrateEvents(opts: HydrateEventOpts): Promise { case 'event_stats': await hydrateEventStats(events); break; + case 'user': + await hydrateUsers({ events, storage, signal }); + break; } } @@ -48,6 +52,23 @@ async function hydrateAuthors(opts: Omit): Promis return events; } +async function hydrateUsers(opts: Omit): Promise { + const { events, storage, signal } = opts; + + const pubkeys = new Set([...events].map((event) => event.pubkey)); + + const users = await storage.query( + [{ kinds: [30361], authors: [Conf.pubkey], '#d': [...pubkeys], limit: pubkeys.size }], + { signal }, + ); + + for (const event of events) { + event.user = users.find((user) => user.tags.find(([name]) => name === 'd')?.[1] === event.pubkey); + } + + return events; +} + async function hydrateAuthorStats(events: DittoEvent[]): Promise { const results = await db .selectFrom('author_stats')