mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
MOves replies formatter out of incoming
This commit is contained in:
parent
0d4f6851b9
commit
5a3bc37bca
2 changed files with 24 additions and 18 deletions
|
@ -13,7 +13,8 @@ def get_status(status):
|
|||
''' create activitypub json for a status '''
|
||||
user = status.user
|
||||
uri = status.absolute_id
|
||||
reply_parent_id = status.reply_parent.absolute_id if status.reply_parent else None
|
||||
reply_parent_id = status.reply_parent.absolute_id \
|
||||
if status.reply_parent else None
|
||||
status_json = {
|
||||
'id': uri,
|
||||
'url': uri,
|
||||
|
@ -42,4 +43,19 @@ def get_status(status):
|
|||
return status_json
|
||||
|
||||
|
||||
|
||||
def get_replies(status, replies):
|
||||
''' collection of replies '''
|
||||
id_slug = status.absolute_id + '/replies'
|
||||
# TODO only partially implemented
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': id_slug,
|
||||
'type': 'Collection',
|
||||
'first': {
|
||||
'id': '%s?page=true' % id_slug,
|
||||
'type': 'CollectionPage',
|
||||
'next': '%s?only_other_accounts=true&page=true' % id_slug,
|
||||
'partOf': id_slug,
|
||||
'items': [get_status(r) for r in replies]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ from fedireads import models
|
|||
from fedireads import outgoing
|
||||
from fedireads.status import create_review, create_status
|
||||
from fedireads.remote_user import get_or_create_remote_user
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
@ -140,24 +139,15 @@ def get_replies(request, username, status_id):
|
|||
if request.method != 'GET':
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
status = models.Status.objects.get(id=status_id)
|
||||
if status.user.localname != username:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
replies = models.Status.objects.filter(
|
||||
reply_parent=status_id
|
||||
reply_parent=status
|
||||
).first()
|
||||
|
||||
path_id = 'https://%s/user/%s/status/%s/replies' % \
|
||||
(DOMAIN, username, status_id)
|
||||
replies_activity = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': path_id,
|
||||
'type': 'Collection',
|
||||
'first': {
|
||||
'id': '%s?page=true' % path_id,
|
||||
'type': 'CollectionPage',
|
||||
'next': '%s?only_other_accounts=true&page=true' % path_id,
|
||||
'partOf': path_id,
|
||||
'items': [activitypub.get_status(replies)]
|
||||
}
|
||||
}
|
||||
replies_activity = activitypub.get_replies(status, replies)
|
||||
return JsonResponse(replies_activity)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue