From 5a3bc37bca9c657838619605573ed6754a9fe9aa Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 17 Feb 2020 21:50:30 -0800 Subject: [PATCH] MOves replies formatter out of incoming --- fedireads/activitypub/status.py | 20 ++++++++++++++++++-- fedireads/incoming.py | 22 ++++++---------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/fedireads/activitypub/status.py b/fedireads/activitypub/status.py index 58168a055..2f474f669 100644 --- a/fedireads/activitypub/status.py +++ b/fedireads/activitypub/status.py @@ -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] + } + } diff --git a/fedireads/incoming.py b/fedireads/incoming.py index 348d62db0..9059f4c14 100644 --- a/fedireads/incoming.py +++ b/fedireads/incoming.py @@ -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)