From deea5be4521f0428a82f51d990bd5d67758dd80a Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 22 Jul 2018 12:04:18 +0200 Subject: [PATCH] Drop more OStatus stuff --- activitypub.py | 2 +- tasks.py | 40 ++++++++++++++++++++++++++++++---------- utils/lookup.py | 2 +- utils/opengraph.py | 1 + 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/activitypub.py b/activitypub.py index 02690ac..ed1a690 100644 --- a/activitypub.py +++ b/activitypub.py @@ -16,8 +16,8 @@ from little_boxes import strtobool from little_boxes.activitypub import _to_list from little_boxes.backend import Backend from little_boxes.errors import ActivityGoneError -from little_boxes.errors import NotAnActivityError from little_boxes.errors import Error +from little_boxes.errors import NotAnActivityError from config import BASE_URL from config import DB diff --git a/tasks.py b/tasks.py index 8710422..5793e8b 100644 --- a/tasks.py +++ b/tasks.py @@ -6,9 +6,9 @@ import random import requests from celery import Celery from little_boxes import activitypub as ap -from little_boxes.errors import NotAnActivityError from little_boxes.errors import ActivityGoneError from little_boxes.errors import ActivityNotFoundError +from little_boxes.errors import NotAnActivityError from little_boxes.httpsig import HTTPSigAuth from little_boxes.linked_data_sig import generate_signature from requests.exceptions import HTTPError @@ -44,10 +44,17 @@ def process_new_activity(self, iri: str) -> None: # Is the activity expected? # following = ap.get_backend().following() should_forward = False + should_delete = False tag_stream = False if activity.has_type(ap.ActivityType.ANNOUNCE): tag_stream = True + try: + activity.get_object() + except NotAnActivityError: + # Most likely on OStatus notice + tag_stream = False + should_delete = True elif activity.has_type(ap.ActivityType.CREATE): note = activity.get_object() @@ -56,13 +63,17 @@ def process_new_activity(self, iri: str) -> None: tag_stream = True if note.inReplyTo: - reply = ap.fetch_remote_activity(note.inReplyTo) - if ( - reply.id.startswith(ID) or reply.has_mention(ID) - ) and activity.is_public(): - # The reply is public "local reply", forward the reply (i.e. the original activity) to the original - # recipients - should_forward = True + try: + reply = ap.fetch_remote_activity(note.inReplyTo) + if ( + reply.id.startswith(ID) or reply.has_mention(ID) + ) and activity.is_public(): + # The reply is public "local reply", forward the reply (i.e. the original activity) to the + # original recipients + should_forward = True + except NotAnActivityError: + # Most likely a reply to an OStatus notce + should_delete = True # (partial) Ghost replies handling # [X] This is the first time the server has seen this Activity. @@ -82,7 +93,7 @@ def process_new_activity(self, iri: str) -> None: note = DB.activities.find_one( {"activity.object.id": activity.get_object().id} ) - if note["meta"].get("forwarded", False): + if note and note["meta"].get("forwarded", False): # If the activity was originally forwarded, forward the delete too should_forward = True @@ -90,10 +101,19 @@ def process_new_activity(self, iri: str) -> None: log.info(f"will forward {activity!r} to followers") activity.forward(back.followers_as_recipients()) + if should_delete: + log.info(f"will soft delete {activity!r}") + log.info(f"{iri} tag_stream={tag_stream}") DB.activities.update_one( {"remote_id": activity.id}, - {"$set": {"meta.stream": tag_stream, "meta.forwarded": should_forward}}, + { + "$set": { + "meta.stream": tag_stream, + "meta.forwarded": should_forward, + "meta.deleted": should_delete, + } + }, ) log.info(f"new activity {iri} processed") diff --git a/utils/lookup.py b/utils/lookup.py index 8e2d760..3bb4756 100644 --- a/utils/lookup.py +++ b/utils/lookup.py @@ -3,8 +3,8 @@ import json import little_boxes.activitypub as ap import mf2py import requests -from little_boxes.webfinger import get_actor_url from little_boxes.errors import NotAnActivityError +from little_boxes.webfinger import get_actor_url def lookup(url: str) -> ap.BaseActivity: diff --git a/utils/opengraph.py b/utils/opengraph.py index b4bd704..87ffa5e 100644 --- a/utils/opengraph.py +++ b/utils/opengraph.py @@ -5,6 +5,7 @@ from little_boxes import activitypub as ap from little_boxes.errors import NotAnActivityError from little_boxes.urlutils import check_url from little_boxes.urlutils import is_url_valid + from .lookup import lookup