diff --git a/src/queries.ts b/src/queries.ts index 1388cd5b..7a9a7dd4 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -22,7 +22,7 @@ const getEvent = async ( const { kind, relations, signal = AbortSignal.timeout(1000) } = opts; const microfilter: IdMicrofilter = { ids: [id] }; - const [memoryEvent] = await memorelay.getFilters([microfilter], opts) as Event[]; + const [memoryEvent] = await memorelay.getFilters([microfilter], opts) as eventsDB.DittoEvent[]; if (memoryEvent && !relations) { return memoryEvent; @@ -36,7 +36,20 @@ const getEvent = async ( const dbEvent = await eventsDB.getFilters([filter], { limit: 1, signal }) .then(([event]) => event); + // TODO: make this DRY-er. + + if (dbEvent && !dbEvent.author) { + const [author] = await memorelay.getFilters([{ kinds: [0], authors: [dbEvent.pubkey] }], opts); + dbEvent.author = author; + } + if (dbEvent) return dbEvent; + + if (memoryEvent && !memoryEvent.author) { + const [author] = await memorelay.getFilters([{ kinds: [0], authors: [memoryEvent.pubkey] }], opts); + memoryEvent.author = author; + } + if (memoryEvent) return memoryEvent; return await reqmeister.req(microfilter).catch(() => undefined) as Event | undefined;