Add familiar followers endpoint

This commit is contained in:
Andrew Godwin 2022-12-21 16:21:40 +00:00
parent 3f37c7ffe7
commit beff63bbac
2 changed files with 32 additions and 0 deletions

View File

@ -165,3 +165,8 @@ class Relationship(Schema):
class Context(Schema): class Context(Schema):
ancestors: list[Status] ancestors: list[Status]
descendants: list[Status] descendants: list[Status]
class FamiliarFollowers(Schema):
id: str
accounts: list[Account]

View File

@ -100,3 +100,30 @@ def account_unfollow(request, id: str):
service = IdentityService(identity) service = IdentityService(identity)
service.unfollow_from(request.identity) service.unfollow_from(request.identity)
return service.mastodon_json_relationship(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