mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 05:24:22 +01:00
hydrate: build fallback authors during gatherAuthors step
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user