mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Add familiar followers endpoint
This commit is contained in:
parent
3f37c7ffe7
commit
beff63bbac
2 changed files with 32 additions and 0 deletions
|
@ -165,3 +165,8 @@ class Relationship(Schema):
|
|||
class Context(Schema):
|
||||
ancestors: list[Status]
|
||||
descendants: list[Status]
|
||||
|
||||
|
||||
class FamiliarFollowers(Schema):
|
||||
id: str
|
||||
accounts: list[Account]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue