diff --git a/api/schemas.py b/api/schemas.py index 59f9a12..727bf4f 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -165,3 +165,8 @@ class Relationship(Schema): class Context(Schema): ancestors: list[Status] descendants: list[Status] + + +class FamiliarFollowers(Schema): + id: str + accounts: list[Account] diff --git a/api/views/accounts.py b/api/views/accounts.py index 47d91c6..c9fe42d 100644 --- a/api/views/accounts.py +++ b/api/views/accounts.py @@ -100,3 +100,30 @@ def account_unfollow(request, id: str): service = IdentityService(identity) service.unfollow_from(request.identity) return service.mastodon_json_relationship(request.identity) + + +@api_router.get( + "/v1/accounts/familiar_followers", response=list[schemas.FamiliarFollowers] +) +@identity_required +def familiar_followers(request): + """ + Returns people you follow that also follow given account IDs + """ + ids = request.GET.getlist("id[]") + result = [] + for id in ids: + target_identity = get_object_or_404(Identity, pk=id) + result.append( + { + "id": id, + "accounts": [ + identity.to_mastodon_json() + for identity in Identity.objects.filter( + inbound_follows__source=request.identity, + outbound_follows__target=target_identity, + )[:20] + ], + } + ) + return result