mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
parent
1c3e0b9379
commit
ee56ae86ec
3 changed files with 41 additions and 6 deletions
|
@ -5,4 +5,4 @@ from .collection import get_outbox, get_outbox_page, get_add, get_remove, \
|
|||
from .create import get_create
|
||||
from .follow import get_follow_request, get_unfollow, get_accept
|
||||
from .status import get_review, get_review_article, get_status, get_replies, \
|
||||
get_favorite, get_add_tag, get_remove_tag
|
||||
get_favorite, get_add_tag, get_remove_tag, get_replies_page
|
||||
|
|
|
@ -71,11 +71,29 @@ def get_replies(status, replies):
|
|||
'type': 'CollectionPage',
|
||||
'next': '%s?only_other_accounts=true&page=true' % id_slug,
|
||||
'partOf': id_slug,
|
||||
'items': [get_status(r) for r in replies]
|
||||
'items': [get_status(r) for r in replies],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_replies_page(status, replies):
|
||||
id_slug = status.absolute_id + '/replies?page=true&only_other_accounts=true'
|
||||
items = []
|
||||
for reply in replies:
|
||||
if reply.user.local:
|
||||
items.append(get_status(reply))
|
||||
else:
|
||||
items.append(reply.remote_id)
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': id_slug,
|
||||
'type': 'CollectionPage',
|
||||
'next': '%s&min_id=%d' % (id_slug, replies[len(replies) - 1].id),
|
||||
'partOf': status.absolute_id + '/replies',
|
||||
'items': [items]
|
||||
}
|
||||
|
||||
|
||||
def get_favorite(favorite):
|
||||
''' like a post '''
|
||||
return {
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.http import HttpResponse, HttpResponseBadRequest, \
|
|||
HttpResponseNotFound, JsonResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
import django.db.utils
|
||||
from django.db.models import Q
|
||||
import json
|
||||
import requests
|
||||
|
||||
|
@ -162,11 +163,27 @@ def get_replies(request, username, status_id):
|
|||
return HttpResponseNotFound()
|
||||
|
||||
replies = models.Status.objects.filter(
|
||||
reply_parent=status
|
||||
).first()
|
||||
reply_parent=status,
|
||||
).select_subclasses()
|
||||
|
||||
replies_activity = activitypub.get_replies(status, [replies])
|
||||
return JsonResponse(replies_activity)
|
||||
if request.GET.get('only_other_accounts'):
|
||||
replies = replies.filter(
|
||||
~Q(user=status.user)
|
||||
)
|
||||
else:
|
||||
replies = replies.filter(user=status.user)
|
||||
|
||||
if request.GET.get('page'):
|
||||
min_id = request.GET.get('min_id')
|
||||
if min_id:
|
||||
replies = replies.filter(id__gt=min_id)
|
||||
max_id = request.GET.get('max_id')
|
||||
if max_id:
|
||||
replies = replies.filter(id__lte=max_id)
|
||||
activity = activitypub.get_replies_page(status, replies)
|
||||
return JsonResponse(activity)
|
||||
|
||||
return JsonResponse(activitypub.get_replies(status, replies))
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
|
Loading…
Reference in a new issue