diff --git a/activitypub.py b/activitypub.py index b46a36f..8aaf85c 100644 --- a/activitypub.py +++ b/activitypub.py @@ -479,7 +479,9 @@ class MicroblogPubBackend(Backend): question = create.get_object() if question.has_type(ap.ActivityType.QUESTION): now = datetime.now(timezone.utc) - dt = parser.parse(question.closed or question.endTime).astimezone(timezone.utc) + dt = parser.parse(question.closed or question.endTime).astimezone( + timezone.utc + ) minutes = int((dt - now).total_seconds() / 60) Tasks.fetch_remote_question(create.id, minutes) diff --git a/app.py b/app.py index ce0efea..d7be285 100644 --- a/app.py +++ b/app.py @@ -1817,7 +1817,7 @@ def inbox(): "failed to verify request, trying to verify the payload by fetching the remote" ) try: - data = get_backend().fetch_iri(data["id"]) + remote_data = get_backend().fetch_iri(data["id"]) except ActivityGoneError: # XXX Mastodon sends Delete activities that are not dereferencable, it's the actor url with #delete # appended, so an `ActivityGoneError` kind of ensure it's "legit" @@ -1831,6 +1831,11 @@ def inbox(): except Exception: logger.exception(f"failed to fetch remote for payload {data!r}") + # Friendica does not returns a 410, but a 302 that redirect to an HTML page + if ap._has_type(data["type"], ActivityType.DELETE): + logger.info(f"received a Delete for an unknown actor {data!r}, drop it") + return Response(status=201) + # Track/store the payload for analysis ip, geoip = _get_ip() @@ -1856,6 +1861,9 @@ def inbox(): } ), ) + + # We fetched the remote data successfully + data = remote_data print(data) activity = ap.parse_activity(data) logger.debug(f"inbox activity={activity}/{data}")