diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 2896b96b..22c9a63f 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -59,7 +59,7 @@ const createAccountController: AppController = async (c) => { const verifyCredentialsController: AppController = async (c) => { const pubkey = c.get('pubkey')!; - const event = await getAuthor(pubkey); + const event = await getAuthor(pubkey, { relations: ['author_stats'] }); if (event) { return c.json(await renderAccount(event, { withSource: true })); } else { @@ -138,7 +138,15 @@ const accountStatusesController: AppController = async (c) => { return c.json([]); } - const filter: DittoFilter<1> = { authors: [pubkey], kinds: [1], relations: ['author'], since, until, limit }; + const filter: DittoFilter<1> = { + authors: [pubkey], + kinds: [1], + relations: ['author', 'event_stats', 'author_stats'], + since, + until, + limit, + }; + if (tagged) { filter['#t'] = [tagged]; } @@ -257,7 +265,9 @@ const favouritesController: AppController = async (c) => { .map((event) => event.tags.find((tag) => tag[0] === 'e')?.[1]) .filter((id): id is string => !!id); - const events1 = await mixer.getFilters([{ kinds: [1], ids, relations: ['author'] }], { timeout: Time.seconds(1) }); + const events1 = await mixer.getFilters([{ kinds: [1], ids, relations: ['author', 'event_stats', 'author_stats'] }], { + timeout: Time.seconds(1), + }); const statuses = await Promise.all(events1.map((event) => renderStatus(event, c.get('pubkey')))); return paginated(c, events1, statuses); diff --git a/src/controllers/api/search.ts b/src/controllers/api/search.ts index b0f71cef..e5f1778c 100644 --- a/src/controllers/api/search.ts +++ b/src/controllers/api/search.ts @@ -69,7 +69,7 @@ function searchEvents({ q, type, limit, account_id }: SearchQuery): Promise ({ ...filter, relations: ['author'] })); + return filters; } export { searchController }; diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 114923da..cf0446a3 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -29,7 +29,7 @@ const createStatusSchema = z.object({ const statusController: AppController = async (c) => { const id = c.req.param('id'); - const event = await getEvent(id, { kind: 1, relations: ['author'] }); + const event = await getEvent(id, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] }); if (event) { return c.json(await renderStatus(event, c.get('pubkey'))); } @@ -89,7 +89,7 @@ const createStatusController: AppController = async (c) => { const contextController: AppController = async (c) => { const id = c.req.param('id'); - const event = await getEvent(id, { kind: 1, relations: ['author'] }); + const event = await getEvent(id, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] }); async function renderStatuses(events: Event<1>[]) { const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey')))); @@ -110,7 +110,7 @@ const contextController: AppController = async (c) => { const favouriteController: AppController = async (c) => { const id = c.req.param('id'); - const target = await getEvent(id, { kind: 1, relations: ['author'] }); + const target = await getEvent(id, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] }); if (target) { await createEvent({ diff --git a/src/controllers/api/timelines.ts b/src/controllers/api/timelines.ts index d3ffcdc4..a29cdc89 100644 --- a/src/controllers/api/timelines.ts +++ b/src/controllers/api/timelines.ts @@ -35,7 +35,7 @@ const hashtagTimelineController: AppController = (c) => { /** Render statuses for timelines. */ async function renderStatuses(c: AppContext, filters: DittoFilter<1>[]) { const events = await mixer.getFilters( - filters.map((filter) => ({ ...filter, relations: ['author'] })), + filters.map((filter) => ({ ...filter, relations: ['author', 'event_stats', 'author_stats'] })), { timeout: Time.seconds(1) }, ); diff --git a/src/queries.ts b/src/queries.ts index de9bd33e..edd5f4aa 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -27,8 +27,14 @@ const getEvent = async ( }; /** Get a Nostr `set_medatadata` event for a user's pubkey. */ -const getAuthor = async (pubkey: string, timeout = 1000): Promise | undefined> => { - const [event] = await mixer.getFilters([{ authors: [pubkey], kinds: [0], limit: 1 }], { limit: 1, timeout }); +const getAuthor = async (pubkey: string, opts: GetEventOpts<0> = {}): Promise | undefined> => { + const { relations, timeout = 1000 } = opts; + + const [event] = await mixer.getFilters( + [{ authors: [pubkey], relations, kinds: [0], limit: 1 }], + { limit: 1, timeout }, + ); + return event; }; @@ -60,7 +66,7 @@ async function getAncestors(event: Event<1>, result = [] as Event<1>[]): Promise const inReplyTo = replyTag ? replyTag[1] : undefined; if (inReplyTo) { - const parentEvent = await getEvent(inReplyTo, { kind: 1, relations: ['author'] }); + const parentEvent = await getEvent(inReplyTo, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] }); if (parentEvent) { result.push(parentEvent); @@ -73,7 +79,10 @@ async function getAncestors(event: Event<1>, result = [] as Event<1>[]): Promise } function getDescendants(eventId: string): Promise[]> { - return mixer.getFilters([{ kinds: [1], '#e': [eventId], relations: ['author'] }], { limit: 200, timeout: 2000 }); + return mixer.getFilters( + [{ kinds: [1], '#e': [eventId], relations: ['author', 'event_stats', 'author_stats'] }], + { limit: 200, timeout: 2000 }, + ); } /** Returns whether the pubkey is followed by a local user. */ diff --git a/src/views.ts b/src/views.ts index 30497108..2314a844 100644 --- a/src/views.ts +++ b/src/views.ts @@ -15,7 +15,7 @@ async function renderEventAccounts(c: AppContext, filters: Filter[]) { } const accounts = await Promise.all([...pubkeys].map(async (pubkey) => { - const author = await getAuthor(pubkey); + const author = await getAuthor(pubkey, { relations: ['author_stats'] }); if (author) { return renderAccount(author); } diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index 120ba93a..17b16770 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -86,8 +86,8 @@ async function renderStatus(event: eventsDB.DittoEvent<1>, viewerPubkey?: string } async function toMention(pubkey: string) { - const profile = await getAuthor(pubkey); - const account = profile ? await renderAccount(profile) : undefined; + const author = await getAuthor(pubkey); + const account = author ? await renderAccount(author) : undefined; if (account) { return {