Implement familiar followers

This commit is contained in:
Alex Gleason 2024-05-24 22:30:56 -05:00
parent ca755b6d77
commit 622a2b2a4f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 25 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import {
accountSearchController, accountSearchController,
accountStatusesController, accountStatusesController,
createAccountController, createAccountController,
familiarFollowersController,
favouritesController, favouritesController,
followController, followController,
followersController, 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/search', accountSearchController);
app.get('/api/v1/accounts/lookup', accountLookupController); app.get('/api/v1/accounts/lookup', accountLookupController);
app.get('/api/v1/accounts/relationships', requireSigner, relationshipsController); 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}}/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}}/unblock', requireSigner, unblockController);
app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/mute', requireSigner, muteController); app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/mute', requireSigner, muteController);

View File

@ -402,6 +402,28 @@ const favouritesController: AppController = async (c) => {
return paginated(c, events1, statuses); 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 { export {
accountController, accountController,
accountLookupController, accountLookupController,
@ -409,6 +431,7 @@ export {
accountStatusesController, accountStatusesController,
blockController, blockController,
createAccountController, createAccountController,
familiarFollowersController,
favouritesController, favouritesController,
followController, followController,
followersController, followersController,