forked from forks/microblog.pub
Cleanup reply delete
This commit is contained in:
parent
84a6d0c498
commit
d5f25e37cf
4 changed files with 15 additions and 22 deletions
10
app.py
10
app.py
|
@ -258,7 +258,15 @@ def proxy(scheme: str, url: str) -> Any:
|
||||||
k: v
|
k: v
|
||||||
for k, v in dict(resp.raw.headers).items()
|
for k, v in dict(resp.raw.headers).items()
|
||||||
if k.lower()
|
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)
|
return Response(data(), headers=resp_headers)
|
||||||
|
|
||||||
|
|
|
@ -410,20 +410,6 @@ class MicroblogPubBackend(Backend):
|
||||||
|
|
||||||
return data
|
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):
|
def embed_collection(total_items, first_page_id):
|
||||||
"""Helper creating a root OrderedCollection with a link to the first page."""
|
"""Helper creating a root OrderedCollection with a link to the first page."""
|
||||||
|
|
|
@ -20,8 +20,6 @@ from core.meta import by_type
|
||||||
from core.meta import in_inbox
|
from core.meta import in_inbox
|
||||||
from core.meta import inc
|
from core.meta import inc
|
||||||
from core.meta import upsert
|
from core.meta import upsert
|
||||||
from core.shared import MY_PERSON
|
|
||||||
from core.shared import back
|
|
||||||
from core.tasks import Tasks
|
from core.tasks import Tasks
|
||||||
from utils import now
|
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}")
|
_logger.info(f"inbox_delete handle_replies obj={obj!r}")
|
||||||
in_reply_to = obj.get_in_reply_to() if obj.inReplyTo else None
|
in_reply_to = obj.get_in_reply_to() if obj.inReplyTo else None
|
||||||
if obj.has_type(ap.CREATE_TYPES):
|
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(
|
in_reply_to = ap._get_id(
|
||||||
DB.activities.find_one(
|
DB.activities.find_one(post_query)["activity"]["object"].get(
|
||||||
{"meta.object_id": obj_id, "type": ap.ActivityType.CREATE.value}
|
"inReplyTo"
|
||||||
)["activity"]["object"].get("inReplyTo")
|
)
|
||||||
)
|
)
|
||||||
if in_reply_to:
|
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:
|
except Exception:
|
||||||
_logger.exception(f"failed to handle delete replies for {obj_id}")
|
_logger.exception(f"failed to handle delete replies for {obj_id}")
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ def clean_html(html):
|
||||||
try:
|
try:
|
||||||
return bleach.clean(html, tags=ALLOWED_TAGS, strip=True)
|
return bleach.clean(html, tags=ALLOWED_TAGS, strip=True)
|
||||||
except Exception:
|
except Exception:
|
||||||
return ""
|
return "failed to clean HTML"
|
||||||
|
|
||||||
|
|
||||||
@filters.app_template_filter()
|
@filters.app_template_filter()
|
||||||
|
|
Loading…
Reference in a new issue