From 2dfde337cd4ddab0bcc27930fd938e5a2010776a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 Jan 2025 21:53:45 -0600 Subject: [PATCH] Fix localSuggestionsController --- src/controllers/api/suggestions.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/controllers/api/suggestions.ts b/src/controllers/api/suggestions.ts index e2357c1a..c939b1ab 100644 --- a/src/controllers/api/suggestions.ts +++ b/src/controllers/api/suggestions.ts @@ -93,18 +93,34 @@ export const localSuggestionsController: AppController = async (c) => { const params = c.get('pagination'); const store = c.get('store'); - const events = await store.query( - [{ kinds: [0], search: `domain:${Conf.url.host}`, ...params }], + const grants = await store.query( + [{ kinds: [30360], authors: [Conf.pubkey], ...params }], + { signal }, + ); + + const pubkeys = new Set(); + + for (const grant of grants) { + const pubkey = grant.tags.find(([name]) => name === 'p')?.[1]; + if (pubkey) { + pubkeys.add(pubkey); + } + } + + const profiles = await store.query( + [{ kinds: [0], authors: [...pubkeys], search: `domain:${Conf.url.host}`, ...params }], { signal }, ) .then((events) => hydrateEvents({ store, events, signal })); - const suggestions = await Promise.all(events.map(async (event) => { + const suggestions = await Promise.all([...pubkeys].map(async (pubkey) => { + const profile = profiles.find((event) => event.pubkey === pubkey); + return { source: 'global', - account: await renderAccount(event), + account: profile ? await renderAccount(profile) : await accountFromPubkey(pubkey), }; })); - return paginated(c, events, suggestions); + return paginated(c, grants, suggestions); };