diff --git a/src/app.ts b/src/app.ts index fbc1ef2..36b0d34 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,6 +13,7 @@ import { accountSearchController, accountStatusesController, createAccountController, + familiarFollowersController, favouritesController, followController, followersController, @@ -156,6 +157,7 @@ app.patch('/api/v1/accounts/update_credentials', requireSigner, updateCredential app.get('/api/v1/accounts/search', accountSearchController); app.get('/api/v1/accounts/lookup', accountLookupController); app.get('/api/v1/accounts/relationships', requireSigner, relationshipsController); +app.get('/api/v1/accounts/familiar_followers', requireSigner, familiarFollowersController); app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/block', requireSigner, blockController); app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/unblock', requireSigner, unblockController); app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/mute', requireSigner, muteController); diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 9600f05..55964a0 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -402,6 +402,28 @@ const favouritesController: AppController = async (c) => { return paginated(c, events1, statuses); }; +const familiarFollowersController: AppController = async (c) => { + const store = await Storages.db(); + const signer = c.get('signer')!; + const pubkey = await signer.getPublicKey(); + + const ids = z.array(z.string()).parse(c.req.queries('id[]')); + const follows = await getFollowedPubkeys(pubkey); + + const results = await Promise.all(ids.map(async (id) => { + const followLists = await store.query([{ kinds: [3], authors: follows, '#p': [id] }]) + .then((events) => hydrateEvents({ events, store })); + + const accounts = await Promise.all( + followLists.map((event) => event.author ? renderAccount(event.author) : accountFromPubkey(event.pubkey)), + ); + + return { id, accounts }; + })); + + return c.json(results); +}; + export { accountController, accountLookupController, @@ -409,6 +431,7 @@ export { accountStatusesController, blockController, createAccountController, + familiarFollowersController, favouritesController, followController, followersController,