Fix thread hydration

This commit is contained in:
Alex Gleason 2024-06-05 11:04:25 -05:00
parent c5c4f47bc2
commit f7a9bf9ffd
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 8 additions and 4 deletions

View File

@ -220,6 +220,12 @@ const contextController: AppController = async (c) => {
getDescendants(store, event.id).then(renderStatuses), getDescendants(store, event.id).then(renderStatuses),
]); ]);
await hydrateEvents({
events: [...ancestors, ...descendants],
signal: c.req.raw.signal,
store,
});
return c.json({ ancestors, descendants }); return c.json({ ancestors, descendants });
} }

View File

@ -74,7 +74,7 @@ async function getAncestors(store: NStore, event: NostrEvent, result: NostrEvent
const inReplyTo = replyTag ? replyTag[1] : undefined; const inReplyTo = replyTag ? replyTag[1] : undefined;
if (inReplyTo) { if (inReplyTo) {
const parentEvent = await getEvent(inReplyTo, { kind: 1 }); const [parentEvent] = await store.query([{ ids: [inReplyTo], limit: 1 }]);
if (parentEvent) { if (parentEvent) {
result.push(parentEvent); result.push(parentEvent);
@ -91,11 +91,9 @@ async function getDescendants(
eventId: string, eventId: string,
signal = AbortSignal.timeout(2000), signal = AbortSignal.timeout(2000),
): Promise<NostrEvent[]> { ): Promise<NostrEvent[]> {
const events = await store return await store
.query([{ kinds: [1], '#e': [eventId], limit: 200 }], { signal }) .query([{ kinds: [1], '#e': [eventId], limit: 200 }], { signal })
.then((events) => events.filter(({ tags }) => findReplyTag(tags)?.[1] === eventId)); .then((events) => events.filter(({ tags }) => findReplyTag(tags)?.[1] === eventId));
return hydrateEvents({ events, store, signal });
} }
/** Returns whether the pubkey is followed by a local user. */ /** Returns whether the pubkey is followed by a local user. */