diff --git a/activitypub.py b/activitypub.py index feb6dae..547b957 100644 --- a/activitypub.py +++ b/activitypub.py @@ -3,7 +3,6 @@ import json import logging import os from datetime import datetime -from enum import Enum from typing import Any from typing import Dict from typing import List @@ -133,7 +132,9 @@ class MicroblogPubBackend(Backend): except Exception: # TODO(tsileo): should be ValueError, but replies trigger a KeyError on object pass object_visibility = None - if activity.has_type([ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE]): + if activity.has_type( + [ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE, ap.ActivityType.LIKE] + ): object_visibility = ap.get_visibility(activity.get_object()).name actor_id = activity.get_actor().id diff --git a/app.py b/app.py index 88bec37..bfa0d12 100644 --- a/app.py +++ b/app.py @@ -2005,6 +2005,8 @@ def inbox(): # POST/ inbox try: data = request.get_json(force=True) + if not isinstance(data, dict): + raise ValueError("not a dict") except Exception: return Response( status=422, @@ -2018,9 +2020,15 @@ def inbox(): and is_blacklisted(data["id"]) or ( "object" in data + and isinstance(data["object"], dict) and "id" in data["object"] and is_blacklisted(data["object"]["id"]) ) + or ( + "object" in data + and isinstance(data["object"], str) + and is_blacklisted(data["object"]) + ) ): logger.info(f"dropping activity from blacklisted host: {data['id']}") return Response(status=201) @@ -3067,13 +3075,6 @@ def task_cache_actor() -> str: if activity.has_type(ap.ActivityType.CREATE): Tasks.fetch_og_meta(iri) - # Cache the object if it's a `Like` or an `Announce` unrelated to the server outbox (because it will never get - # displayed) - if activity.has_type( - [ap.ActivityType.LIKE, ap.ActivityType.ANNOUNCE] - ) and not activity.get_object_id().startswith(BASE_URL): - Tasks.cache_object(iri) - actor = activity.get_actor() if actor.icon: if isinstance(actor.icon, dict) and "url" in actor.icon: @@ -3212,14 +3213,6 @@ def task_process_new_activity(): # If the activity was originally forwarded, forward the delete too should_forward = True - elif activity.has_type(ap.ActivityType.LIKE): - if activity.get_object_id().startswith(BASE_URL): - should_keep = True - else: - # We only want to keep a like if it's a like for a local activity - # (Pleroma relay the likes it received, we don't want to store them) - should_delete = True - if should_forward: app.logger.info(f"will forward {activity!r} to followers") Tasks.forward_activity(activity.id) diff --git a/templates/stream.html b/templates/stream.html index bc55421..178a190 100644 --- a/templates/stream.html +++ b/templates/stream.html @@ -7,7 +7,7 @@