renderEventAccounts: rework the logic, call hydrateEvents
This commit is contained in:
parent
4d9b4d9475
commit
b33f7d2cc4
28
src/views.ts
28
src/views.ts
|
@ -1,4 +1,5 @@
|
||||||
import { NostrFilter } from '@nostrify/nostrify';
|
import { NostrFilter } from '@nostrify/nostrify';
|
||||||
|
|
||||||
import { AppContext } from '@/app.ts';
|
import { AppContext } from '@/app.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
||||||
|
@ -14,23 +15,19 @@ async function renderEventAccounts(c: AppContext, filters: NostrFilter[], signal
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const events = await store.query(filters, { signal });
|
|
||||||
const pubkeys = new Set(events.map(({ pubkey }) => pubkey));
|
|
||||||
|
|
||||||
if (!pubkeys.size) {
|
const events = await store.query(filters, { signal })
|
||||||
return c.json([]);
|
// Deduplicate by author.
|
||||||
}
|
.then((events) => Array.from(new Map(events.map((event) => [event.pubkey, event])).values()))
|
||||||
|
|
||||||
const authors = await store.query([{ kinds: [0], authors: [...pubkeys] }], { signal })
|
|
||||||
.then((events) => hydrateEvents({ events, store, signal }));
|
.then((events) => hydrateEvents({ events, store, signal }));
|
||||||
|
|
||||||
const accounts = await Promise.all(
|
const accounts = await Promise.all(
|
||||||
Array.from(pubkeys).map(async (pubkey) => {
|
events.map(({ author, pubkey }) => {
|
||||||
const event = authors.find((event) => event.pubkey === pubkey);
|
if (author) {
|
||||||
if (event) {
|
return renderAccount(author);
|
||||||
return await renderAccount(event);
|
} else {
|
||||||
|
return accountFromPubkey(pubkey);
|
||||||
}
|
}
|
||||||
return await accountFromPubkey(pubkey);
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -46,12 +43,13 @@ async function renderAccounts(c: AppContext, authors: string[], signal = AbortSi
|
||||||
.then((events) => hydrateEvents({ events, store, signal }));
|
.then((events) => hydrateEvents({ events, store, signal }));
|
||||||
|
|
||||||
const accounts = await Promise.all(
|
const accounts = await Promise.all(
|
||||||
authors.map(async (pubkey) => {
|
authors.map((pubkey) => {
|
||||||
const event = events.find((event) => event.pubkey === pubkey);
|
const event = events.find((event) => event.pubkey === pubkey);
|
||||||
if (event) {
|
if (event) {
|
||||||
return await renderAccount(event);
|
return renderAccount(event);
|
||||||
|
} else {
|
||||||
|
return accountFromPubkey(pubkey);
|
||||||
}
|
}
|
||||||
return await accountFromPubkey(pubkey);
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue