Cleanup reply delete

This commit is contained in:
Thomas Sileo 2019-08-18 18:31:52 +02:00
parent 84a6d0c498
commit d5f25e37cf
4 changed files with 15 additions and 22 deletions

10
app.py
View file

@ -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)

View file

@ -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."""

View file

@ -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}")

View file

@ -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()