From 8f7ee6f2cdf8a5c346ec95da63dd169250ecb0a5 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 21 Jul 2018 01:42:59 +0200 Subject: [PATCH] Forward replies --- tasks.py | 16 ++++++++++++++-- templates/utils.html | 1 - 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tasks.py b/tasks.py index 7824cd3..9656c84 100644 --- a/tasks.py +++ b/tasks.py @@ -15,6 +15,7 @@ from requests.exceptions import HTTPError import activitypub from config import DB from config import HEADERS +from config import ID from config import KEY from config import MEDIA_CACHE from config import USER_AGENT @@ -33,6 +34,7 @@ ap.use_backend(back) @app.task(bind=True, max_retries=12) def process_new_activity(self, iri: str) -> None: + """Process an activity received in the inbox""" try: activity = ap.fetch_remote_activity(iri) log.info(f"activity={activity!r}") @@ -45,7 +47,13 @@ def process_new_activity(self, iri: str) -> None: tag_stream = True elif activity.has_type(ap.ActivityType.CREATE): note = activity.get_object() - if not note.inReplyTo: + if note.inReplyTo: + reply = ap.fetch_remote_activity(note.inReplyTo) + if reply.id.startswith(ID) and activity.is_public(): + # The reply is public "local reply", forward the reply (i.e. the original activity) to the original + # recipients + activity.forward(reply.recipients()) + else: tag_stream = True log.info(f"{iri} tag_stream={tag_stream}") @@ -126,7 +134,11 @@ def post_to_inbox(self, payload: str, to: str) -> None: log.info("payload=%s", payload) log.info("generating sig") signed_payload = json.loads(payload) - generate_signature(signed_payload, KEY) + + # Don't overwrite the signature if we're forwarding an activity + if "signature" not in signed_payload: + generate_signature(signed_payload, KEY) + log.info("to=%s", to) resp = requests.post( to, diff --git a/templates/utils.html b/templates/utils.html index 6d4b84a..3f267b5 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -172,7 +172,6 @@ {% macro display_thread(thread, likes=[], shares=[]) -%} {% for reply in thread %} -{{ reply }} {% if reply._requested %} {{ display_note(reply.activity.object, perma=True, ui=False, likes=likes, shares=shares, meta=reply.meta) }} {% else %}