From d5f25e37cf263e909d520f6333e46c5b7c444489 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 18 Aug 2019 18:31:52 +0200 Subject: [PATCH] Cleanup reply delete --- app.py | 10 +++++++++- core/activitypub.py | 14 -------------- core/inbox.py | 11 +++++------ utils/template_filters.py | 2 +- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app.py b/app.py index ea8c904..2df4049 100644 --- a/app.py +++ b/app.py @@ -258,7 +258,15 @@ def proxy(scheme: str, url: str) -> Any: k: v for k, v in dict(resp.raw.headers).items() if k.lower() - in ["content-type", "etag", "cache-control", "expires", "date", "last-modified"] + in [ + "content-length", + "content-type", + "etag", + "cache-control", + "expires", + "date", + "last-modified", + ] } return Response(data(), headers=resp_headers) diff --git a/core/activitypub.py b/core/activitypub.py index dd4e58e..2d413d1 100644 --- a/core/activitypub.py +++ b/core/activitypub.py @@ -410,20 +410,6 @@ class MicroblogPubBackend(Backend): return data - def set_post_to_remote_inbox(self, cb): - self.post_to_remote_inbox_cb = cb - - def _handle_replies_delete( - self, as_actor: ap.Person, in_reply_to: Optional[str] - ) -> None: - if not in_reply_to: - pass - - DB.activities.update_one( - {"activity.object.id": in_reply_to}, - {"$inc": {"meta.count_reply": -1, "meta.count_direct_reply": -1}}, - ) - def embed_collection(total_items, first_page_id): """Helper creating a root OrderedCollection with a link to the first page.""" diff --git a/core/inbox.py b/core/inbox.py index 0208e85..e9465b5 100644 --- a/core/inbox.py +++ b/core/inbox.py @@ -20,8 +20,6 @@ from core.meta import by_type from core.meta import in_inbox from core.meta import inc from core.meta import upsert -from core.shared import MY_PERSON -from core.shared import back from core.tasks import Tasks from utils import now @@ -47,13 +45,14 @@ def _delete_process_inbox(delete: ap.Delete, new_meta: _NewMeta) -> None: _logger.info(f"inbox_delete handle_replies obj={obj!r}") in_reply_to = obj.get_in_reply_to() if obj.inReplyTo else None if obj.has_type(ap.CREATE_TYPES): + post_query = {**by_object_id(obj_id), **by_type(ap.ActivityType.CREATE)} in_reply_to = ap._get_id( - DB.activities.find_one( - {"meta.object_id": obj_id, "type": ap.ActivityType.CREATE.value} - )["activity"]["object"].get("inReplyTo") + DB.activities.find_one(post_query)["activity"]["object"].get( + "inReplyTo" + ) ) if in_reply_to: - back._handle_replies_delete(MY_PERSON, in_reply_to) + DB.activities.update_one(post_query, inc(MetaKey.COUNT_REPLY, -1)) except Exception: _logger.exception(f"failed to handle delete replies for {obj_id}") diff --git a/utils/template_filters.py b/utils/template_filters.py index 0eb3c7d..e565b15 100644 --- a/utils/template_filters.py +++ b/utils/template_filters.py @@ -95,7 +95,7 @@ def clean_html(html): try: return bleach.clean(html, tags=ALLOWED_TAGS, strip=True) except Exception: - return "" + return "failed to clean HTML" @filters.app_template_filter()