mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-26 09:11:00 +00:00
/v1/statuses/{id}/favourited_by (#324)
This commit is contained in:
parent
52b4384cd6
commit
a93f03d639
1 changed files with 50 additions and 1 deletions
|
@ -1,16 +1,25 @@
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
from django.forms import ValidationError
|
from django.forms import ValidationError
|
||||||
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from ninja import Schema
|
from ninja import Schema
|
||||||
|
|
||||||
from activities.models import Post, PostAttachment, PostInteraction, TimelineEvent
|
from activities.models import (
|
||||||
|
Post,
|
||||||
|
PostAttachment,
|
||||||
|
PostInteraction,
|
||||||
|
PostInteractionStates,
|
||||||
|
TimelineEvent,
|
||||||
|
)
|
||||||
from activities.services import PostService
|
from activities.services import PostService
|
||||||
from api import schemas
|
from api import schemas
|
||||||
from api.views.base import api_router
|
from api.views.base import api_router
|
||||||
from core.models import Config
|
from core.models import Config
|
||||||
|
from users.models import Identity
|
||||||
|
|
||||||
from ..decorators import identity_required
|
from ..decorators import identity_required
|
||||||
|
from ..pagination import MastodonPaginator
|
||||||
|
|
||||||
|
|
||||||
class PostStatusSchema(Schema):
|
class PostStatusSchema(Schema):
|
||||||
|
@ -116,6 +125,46 @@ def unfavourite_status(request, id: str):
|
||||||
return post.to_mastodon_json(interactions=interactions)
|
return post.to_mastodon_json(interactions=interactions)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("/v1/statuses/{id}/favourited_by", response=list[schemas.Account])
|
||||||
|
def favourited_by(
|
||||||
|
request: HttpRequest,
|
||||||
|
response: HttpResponse,
|
||||||
|
id: str,
|
||||||
|
max_id: str | None = None,
|
||||||
|
since_id: str | None = None,
|
||||||
|
min_id: str | None = None,
|
||||||
|
limit: int = 20,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
View who favourited a given status.
|
||||||
|
"""
|
||||||
|
# This method should filter out private statuses, but we don't really have
|
||||||
|
# a concept of "private status" yet.
|
||||||
|
post = get_object_or_404(Post, pk=id)
|
||||||
|
|
||||||
|
paginator = MastodonPaginator(Identity, sort_attribute="published")
|
||||||
|
pager = paginator.paginate(
|
||||||
|
post.interactions.filter(
|
||||||
|
type=PostInteraction.Types.like,
|
||||||
|
state__in=PostInteractionStates.group_active(),
|
||||||
|
)
|
||||||
|
.select_related("identity")
|
||||||
|
.order_by("published"),
|
||||||
|
min_id=min_id,
|
||||||
|
max_id=max_id,
|
||||||
|
since_id=since_id,
|
||||||
|
limit=limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
if pager.results:
|
||||||
|
response.headers["Link"] = pager.link_header(
|
||||||
|
request,
|
||||||
|
["limit"],
|
||||||
|
)
|
||||||
|
|
||||||
|
return [result.identity.to_mastodon_json() for result in pager.results]
|
||||||
|
|
||||||
|
|
||||||
@api_router.post("/v1/statuses/{id}/reblog", response=schemas.Status)
|
@api_router.post("/v1/statuses/{id}/reblog", response=schemas.Status)
|
||||||
@identity_required
|
@identity_required
|
||||||
def reblog_status(request, id: str):
|
def reblog_status(request, id: str):
|
||||||
|
|
Loading…
Reference in a new issue