Merge branch 'familiar-followers' into 'main'

Implement familiar followers

See merge request soapbox-pub/ditto!314
This commit is contained in:
Alex Gleason 2024-05-25 03:39:04 +00:00
commit cf71c48f09
2 changed files with 25 additions and 0 deletions

View File

@ -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);

View File

@ -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,