Implement Mastodon's v1/statuses/<id>/reblogged_by API endpoint (#551)

This commit is contained in:
Christof Dorner 2023-03-31 19:40:15 +00:00 committed by GitHub
parent ba4414dbce
commit 96bc64fd01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -91,6 +91,7 @@ urlpatterns = [
path("v1/statuses/<id>/favourited_by", statuses.favourited_by),
path("v1/statuses/<id>/reblog", statuses.reblog_status),
path("v1/statuses/<id>/unreblog", statuses.unreblog_status),
path("v1/statuses/<id>/reblogged_by", statuses.reblogged_by),
path("v1/statuses/<id>/bookmark", statuses.bookmark_status),
path("v1/statuses/<id>/unbookmark", statuses.unbookmark_status),
# Tags

View File

@ -246,6 +246,48 @@ def favourited_by(
)
@api_view.get
def reblogged_by(
request: HttpRequest,
id: str,
max_id: str | None = None,
since_id: str | None = None,
min_id: str | None = None,
limit: int = 20,
) -> ApiResponse[list[schemas.Account]]:
"""
View who reblogged a given status.
"""
post = post_for_id(request, id)
paginator = MastodonPaginator()
pager: PaginationResult[PostInteraction] = paginator.paginate(
post.interactions.filter(
type=PostInteraction.Types.boost,
state__in=PostInteractionStates.group_active(),
).select_related("identity"),
min_id=min_id,
max_id=max_id,
since_id=since_id,
limit=limit,
)
return PaginatingApiResponse(
[
schemas.Account.from_identity(
interaction.identity,
include_counts=False,
)
for interaction in pager.results
],
request=request,
include_params=[
"limit",
"id",
],
)
@scope_required("write:favourites")
@api_view.post
def reblog_status(request, id: str) -> schemas.Status: