hydrate: build fallback authors during gatherAuthors step

This commit is contained in:
Alex Gleason 2024-10-17 15:26:23 -05:00
parent 33e5b20159
commit 6ea71865f1
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -99,8 +99,7 @@ export function assembleEvents(
}));
for (const event of a) {
event.author = b.find((e) => matchFilter({ kinds: [0], authors: [event.pubkey] }, e)) ??
fallbackAuthor(event.pubkey);
event.author = b.find((e) => matchFilter({ kinds: [0], authors: [event.pubkey] }, e));
event.user = b.find((e) => matchFilter({ kinds: [30382], authors: [admin], '#d': [event.pubkey] }, e));
event.info = b.find((e) => matchFilter({ kinds: [30383], authors: [admin], '#d': [event.id] }, e));
@ -231,19 +230,29 @@ function gatherQuotes({ events, store, signal }: HydrateOpts): Promise<DittoEven
}
/** Collect authors from the events. */
function gatherAuthors({ events, store, signal }: HydrateOpts): Promise<DittoEvent[]> {
async function gatherAuthors({ events, store, signal }: HydrateOpts): Promise<DittoEvent[]> {
const pubkeys = new Set(events.map((event) => {
if (event.kind === 9735) {
if (event.kind === 9735) { // FIXME: This code doesn't belong in this function.
const pubkey = event.tags.find(([name]) => name === 'p')?.[1];
if (pubkey) return pubkey;
}
return event.pubkey;
}));
return store.query(
const authors = await store.query(
[{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }],
{ signal },
);
for (const pubkey of pubkeys) {
const author = authors.find((e) => matchFilter({ kinds: [0], authors: [pubkey] }, e));
if (author) {
const fallback = fallbackAuthor(pubkey);
authors.push(fallback);
}
}
return authors;
}
/** Collect users from the events. */