diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 8a558e5..c81b587 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -253,7 +253,10 @@ const favouriteController: AppController = async (c) => { const favouritedByController: AppController = (c) => { const id = c.req.param('id'); const params = paginationSchema.parse(c.req.query()); - return renderEventAccounts(c, [{ kinds: [7], '#e': [id], ...params }]); + + return renderEventAccounts(c, [{ kinds: [7], '#e': [id], ...params }], { + filterFn: ({ content }) => content === '+', + }); }; /** https://docs.joinmastodon.org/methods/statuses/#boost */ diff --git a/src/views.ts b/src/views.ts index 80a84b5..5b6d8c3 100644 --- a/src/views.ts +++ b/src/views.ts @@ -1,4 +1,4 @@ -import { NostrFilter } from '@nostrify/nostrify'; +import { NostrEvent, NostrFilter } from '@nostrify/nostrify'; import { AppContext } from '@/app.ts'; import { Storages } from '@/storages.ts'; @@ -8,18 +8,26 @@ import { paginated, paginationSchema } from '@/utils/api.ts'; import { hydrateEvents } from '@/storages/hydrate.ts'; import { accountFromPubkey } from '@/views/mastodon/accounts.ts'; +interface RenderEventAccountsOpts { + signal?: AbortSignal; + filterFn?: (event: NostrEvent) => boolean; +} + /** Render account objects for the author of each event. */ -async function renderEventAccounts(c: AppContext, filters: NostrFilter[], signal = AbortSignal.timeout(1000)) { +async function renderEventAccounts(c: AppContext, filters: NostrFilter[], opts?: RenderEventAccountsOpts) { if (!filters.length) { return c.json([]); } + const { signal = AbortSignal.timeout(1000), filterFn } = opts ?? {}; + const store = await Storages.db(); const events = await store.query(filters, { signal }) // Deduplicate by author. .then((events) => Array.from(new Map(events.map((event) => [event.pubkey, event])).values())) - .then((events) => hydrateEvents({ events, store, signal })); + .then((events) => hydrateEvents({ events, store, signal })) + .then((events) => filterFn ? events.filter(filterFn) : events); const accounts = await Promise.all( events.map(({ author, pubkey }) => {