From ade3bee21443f5ba94b750877ce773080acb89d8 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 17 Aug 2019 18:38:15 +0200 Subject: [PATCH] Tweak reply processing --- blueprints/tasks.py | 7 ++++--- core/activitypub.py | 2 +- utils/lookup.py | 5 ++++- utils/nodeinfo.py | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/blueprints/tasks.py b/blueprints/tasks.py index 88056fb..c493da2 100644 --- a/blueprints/tasks.py +++ b/blueprints/tasks.py @@ -572,12 +572,13 @@ def task_process_reply() -> _Response: ) for new_reply in new_replies: - if find_one_activity(by_object_id(new_reply.id)) or DB.replies.find_one( - {"remote_id": root_reply} - ): + if find_one_activity( + {**by_object_id(new_reply.id), **by_type(ap.ActivityType.CREATE)} + ) or DB.replies.find_one(by_remote_id(new_reply.id)): continue actor = new_reply.get_actor() + # Save the reply with the cached actor and the thread flag/ID save_reply( new_reply, { diff --git a/core/activitypub.py b/core/activitypub.py index 4395bae..3f5e908 100644 --- a/core/activitypub.py +++ b/core/activitypub.py @@ -35,11 +35,11 @@ from core.meta import Box from core.meta import MetaKey from core.meta import by_object_id from core.meta import by_remote_id +from core.meta import by_type from core.meta import flag from core.meta import inc from core.meta import upsert from core.tasks import Tasks -from core.meta import by_type from utils import now logger = logging.getLogger(__name__) diff --git a/utils/lookup.py b/utils/lookup.py index d5ddcff..0f2ea2a 100644 --- a/utils/lookup.py +++ b/utils/lookup.py @@ -35,7 +35,10 @@ def lookup(url: str) -> ap.BaseActivity: except requests.RequestException as err: raise RemoteServerUnavailableError(f"failed to GET {url}: {err!r}") - resp.raise_for_status() + try: + resp.raise_for_status() + except Exception: + return ap.fetch_remote_activity(url) # If the page is HTML, maybe it contains an alternate link pointing to an AP object for alternate in mf2py.parse(resp.text).get("alternates", []): diff --git a/utils/nodeinfo.py b/utils/nodeinfo.py index 38f1ba1..40295cc 100644 --- a/utils/nodeinfo.py +++ b/utils/nodeinfo.py @@ -69,7 +69,7 @@ def get_software_name(server: str) -> str: return SoftwareName.UNKNOWN.value except requests.RequestException: - pass + return SoftwareName.UNKNOWN.value if _try_mastodon_api(server): return SoftwareName.MASTODON.value