mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
hydrate: build fallback authors during gatherAuthors step
This commit is contained in:
parent
33e5b20159
commit
6ea71865f1
1 changed files with 14 additions and 5 deletions
|
|
@ -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. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue