MOves replies formatter out of incoming

This commit is contained in:
Mouse Reeve 2020-02-17 21:50:30 -08:00
parent 0d4f6851b9
commit 5a3bc37bca
2 changed files with 24 additions and 18 deletions

View file

@ -13,7 +13,8 @@ def get_status(status):
''' create activitypub json for a status ''' ''' create activitypub json for a status '''
user = status.user user = status.user
uri = status.absolute_id 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 = { status_json = {
'id': uri, 'id': uri,
'url': uri, 'url': uri,
@ -42,4 +43,19 @@ def get_status(status):
return status_json 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]
}
}

View file

@ -14,7 +14,6 @@ from fedireads import models
from fedireads import outgoing from fedireads import outgoing
from fedireads.status import create_review, create_status from fedireads.status import create_review, create_status
from fedireads.remote_user import get_or_create_remote_user from fedireads.remote_user import get_or_create_remote_user
from fedireads.settings import DOMAIN
@csrf_exempt @csrf_exempt
@ -140,24 +139,15 @@ def get_replies(request, username, status_id):
if request.method != 'GET': if request.method != 'GET':
return HttpResponseBadRequest() return HttpResponseBadRequest()
status = models.Status.objects.get(id=status_id)
if status.user.localname != username:
return HttpResponseNotFound()
replies = models.Status.objects.filter( replies = models.Status.objects.filter(
reply_parent=status_id reply_parent=status
).first() ).first()
path_id = 'https://%s/user/%s/status/%s/replies' % \ replies_activity = activitypub.get_replies(status, 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)]
}
}
return JsonResponse(replies_activity) return JsonResponse(replies_activity)