mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-25 09:14:25 +01:00
hydrateEvents: refactor a separate hydrateAuthors function
This commit is contained in:
@@ -17,18 +17,30 @@ async function hydrateEvents(opts: HydrateEventOpts): Promise<DittoEvent[]> {
|
||||
return events;
|
||||
}
|
||||
|
||||
if (relations.includes('author')) {
|
||||
const pubkeys = new Set([...events].map((event) => event.pubkey));
|
||||
const authors = await storage.query([{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }], { signal });
|
||||
|
||||
for (const event of events) {
|
||||
event.author = authors.find((author) => author.pubkey === event.pubkey);
|
||||
for (const relation in relations) {
|
||||
switch (relation) {
|
||||
case 'author':
|
||||
await hydrateAuthors({ events, storage, signal });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
async function hydrateAuthors(opts: Omit<HydrateEventOpts, 'relations'>): Promise<DittoEvent[]> {
|
||||
const { events, storage, signal } = opts;
|
||||
|
||||
const pubkeys = new Set([...events].map((event) => event.pubkey));
|
||||
const authors = await storage.query([{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }], { signal });
|
||||
|
||||
for (const event of events) {
|
||||
event.author = authors.find((author) => author.pubkey === event.pubkey);
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
/** Return a normalized event without any non-standard keys. */
|
||||
function purifyEvent(event: NostrEvent): NostrEvent {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user