Forward replies

This commit is contained in:
Thomas Sileo 2018-07-21 01:42:59 +02:00
parent ea6be0ed8e
commit 8f7ee6f2cd
2 changed files with 14 additions and 3 deletions

View file

@ -15,6 +15,7 @@ from requests.exceptions import HTTPError
import activitypub import activitypub
from config import DB from config import DB
from config import HEADERS from config import HEADERS
from config import ID
from config import KEY from config import KEY
from config import MEDIA_CACHE from config import MEDIA_CACHE
from config import USER_AGENT from config import USER_AGENT
@ -33,6 +34,7 @@ ap.use_backend(back)
@app.task(bind=True, max_retries=12) @app.task(bind=True, max_retries=12)
def process_new_activity(self, iri: str) -> None: def process_new_activity(self, iri: str) -> None:
"""Process an activity received in the inbox"""
try: try:
activity = ap.fetch_remote_activity(iri) activity = ap.fetch_remote_activity(iri)
log.info(f"activity={activity!r}") log.info(f"activity={activity!r}")
@ -45,7 +47,13 @@ def process_new_activity(self, iri: str) -> None:
tag_stream = True tag_stream = True
elif activity.has_type(ap.ActivityType.CREATE): elif activity.has_type(ap.ActivityType.CREATE):
note = activity.get_object() 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 tag_stream = True
log.info(f"{iri} tag_stream={tag_stream}") 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("payload=%s", payload)
log.info("generating sig") log.info("generating sig")
signed_payload = json.loads(payload) signed_payload = json.loads(payload)
# Don't overwrite the signature if we're forwarding an activity
if "signature" not in signed_payload:
generate_signature(signed_payload, KEY) generate_signature(signed_payload, KEY)
log.info("to=%s", to) log.info("to=%s", to)
resp = requests.post( resp = requests.post(
to, to,

View file

@ -172,7 +172,6 @@
{% macro display_thread(thread, likes=[], shares=[]) -%} {% macro display_thread(thread, likes=[], shares=[]) -%}
{% for reply in thread %} {% for reply in thread %}
{{ reply }}
{% if reply._requested %} {% if reply._requested %}
{{ display_note(reply.activity.object, perma=True, ui=False, likes=likes, shares=shares, meta=reply.meta) }} {{ display_note(reply.activity.object, perma=True, ui=False, likes=likes, shares=shares, meta=reply.meta) }}
{% else %} {% else %}