forked from forks/microblog.pub
Improve retry handling
This commit is contained in:
parent
a25a8fb1e1
commit
16e0775717
2 changed files with 15 additions and 13 deletions
|
@ -367,14 +367,14 @@ class MicroblogPubBackend(Backend):
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"inbox_delete handle_replies obj={obj!r}")
|
logger.info(f"inbox_delete handle_replies obj={obj!r}")
|
||||||
in_reply_to = obj.inReplyTo
|
in_reply_to = obj.get_in_reply_to()
|
||||||
if delete.get_object().ACTIVITY_TYPE != ap.ActivityType.NOTE:
|
if delete.get_object().ACTIVITY_TYPE != ap.ActivityType.NOTE:
|
||||||
in_reply_to = DB.activities.find_one(
|
in_reply_to = ap._get_id(DB.activities.find_one(
|
||||||
{
|
{
|
||||||
"activity.object.id": delete.get_object().id,
|
"activity.object.id": delete.get_object().id,
|
||||||
"type": ap.ActivityType.CREATE.value,
|
"type": ap.ActivityType.CREATE.value,
|
||||||
}
|
}
|
||||||
)["activity"]["object"].get("inReplyTo")
|
)["activity"]["object"].get("inReplyTo"))
|
||||||
|
|
||||||
# Fake a Undo so any related Like/Announce doesn't appear on the web UI
|
# Fake a Undo so any related Like/Announce doesn't appear on the web UI
|
||||||
DB.activities.update(
|
DB.activities.update(
|
||||||
|
@ -406,7 +406,7 @@ class MicroblogPubBackend(Backend):
|
||||||
{"$set": {"meta.undo": True, "meta.exta": "object deleted"}},
|
{"$set": {"meta.undo": True, "meta.exta": "object deleted"}},
|
||||||
)
|
)
|
||||||
|
|
||||||
self._handle_replies_delete(as_actor, obj.inReplyTo)
|
self._handle_replies_delete(as_actor, obj.get_in_reply_to())
|
||||||
|
|
||||||
@ensure_it_is_me
|
@ensure_it_is_me
|
||||||
def inbox_update(self, as_actor: ap.Person, update: ap.Update) -> None:
|
def inbox_update(self, as_actor: ap.Person, update: ap.Update) -> None:
|
||||||
|
@ -524,7 +524,7 @@ class MicroblogPubBackend(Backend):
|
||||||
def _handle_replies(self, as_actor: ap.Person, create: ap.Create) -> None:
|
def _handle_replies(self, as_actor: ap.Person, create: ap.Create) -> None:
|
||||||
"""Go up to the root reply, store unknown replies in the `threads` DB and set the "meta.thread_root_parent"
|
"""Go up to the root reply, store unknown replies in the `threads` DB and set the "meta.thread_root_parent"
|
||||||
key to make it easy to query a whole thread."""
|
key to make it easy to query a whole thread."""
|
||||||
in_reply_to = create.get_object().inReplyTo
|
in_reply_to = create.get_object().get_in_reply_to()
|
||||||
if not in_reply_to:
|
if not in_reply_to:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ class MicroblogPubBackend(Backend):
|
||||||
# TODO(tsileo): parses the replies collection and import the replies?
|
# TODO(tsileo): parses the replies collection and import the replies?
|
||||||
|
|
||||||
while reply is not None:
|
while reply is not None:
|
||||||
in_reply_to = reply.inReplyTo
|
in_reply_to = reply.get_in_reply_to()
|
||||||
if not in_reply_to:
|
if not in_reply_to:
|
||||||
break
|
break
|
||||||
root_reply = in_reply_to
|
root_reply = in_reply_to
|
||||||
|
|
16
app.py
16
app.py
|
@ -901,7 +901,7 @@ def _build_thread(data, include_children=True): # noqa: C901
|
||||||
rep_id = rep["activity"]["object"]["id"]
|
rep_id = rep["activity"]["object"]["id"]
|
||||||
if rep_id == root_id:
|
if rep_id == root_id:
|
||||||
continue
|
continue
|
||||||
reply_of = rep["activity"]["object"]["inReplyTo"]
|
reply_of = ap._get_id(rep["activity"]["object"]["inReplyTo"])
|
||||||
try:
|
try:
|
||||||
idx[reply_of]["_nodes"].append(rep)
|
idx[reply_of]["_nodes"].append(rep)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -2544,7 +2544,8 @@ def invalidate_cache(activity):
|
||||||
DB.cache2.remove()
|
DB.cache2.remove()
|
||||||
elif activity.has_type(ap.ActivityType.CREATE):
|
elif activity.has_type(ap.ActivityType.CREATE):
|
||||||
note = activity.get_object()
|
note = activity.get_object()
|
||||||
if not note.inReplyTo or note.inReplyTo.startswith(ID):
|
in_reply_to = note.get_in_reply_to()
|
||||||
|
if not in_reply_to or in_reply_to.startswith(ID):
|
||||||
DB.cache2.remove()
|
DB.cache2.remove()
|
||||||
# FIXME(tsileo): check if it's a reply of a reply
|
# FIXME(tsileo): check if it's a reply of a reply
|
||||||
|
|
||||||
|
@ -2696,19 +2697,20 @@ def task_process_new_activity():
|
||||||
|
|
||||||
elif activity.has_type(ap.ActivityType.CREATE):
|
elif activity.has_type(ap.ActivityType.CREATE):
|
||||||
note = activity.get_object()
|
note = activity.get_object()
|
||||||
|
in_reply_to = note.get_in_reply_to()
|
||||||
# Make the note part of the stream if it's not a reply, or if it's a local reply
|
# Make the note part of the stream if it's not a reply, or if it's a local reply
|
||||||
if not note.inReplyTo or note.inReplyTo.startswith(ID):
|
if not in_reply_to or in_reply_to.startswith(ID):
|
||||||
tag_stream = True
|
tag_stream = True
|
||||||
|
|
||||||
# FIXME(tsileo): check for direct addressing in the to, cc, bcc... fields
|
# FIXME(tsileo): check for direct addressing in the to, cc, bcc... fields
|
||||||
if (note.inReplyTo and note.inReplyTo.startswith(ID)) or note.has_mention(
|
if (in_reply_to and in_reply_to.startswith(ID)) or note.has_mention(
|
||||||
ID
|
ID
|
||||||
):
|
):
|
||||||
should_keep = True
|
should_keep = True
|
||||||
|
|
||||||
if note.inReplyTo:
|
if in_reply_to:
|
||||||
try:
|
try:
|
||||||
reply = ap.fetch_remote_activity(note.inReplyTo)
|
reply = ap.fetch_remote_activity(note.get_in_reply_to())
|
||||||
if (
|
if (
|
||||||
reply.id.startswith(ID) or reply.has_mention(ID)
|
reply.id.startswith(ID) or reply.has_mention(ID)
|
||||||
) and activity.is_public():
|
) and activity.is_public():
|
||||||
|
@ -2731,7 +2733,7 @@ def task_process_new_activity():
|
||||||
should_forward = True
|
should_forward = True
|
||||||
|
|
||||||
# [X] The values of inReplyTo, object, target and/or tag are objects owned by the server
|
# [X] The values of inReplyTo, object, target and/or tag are objects owned by the server
|
||||||
if not (note.inReplyTo and note.inReplyTo.startswith(ID)):
|
if not (in_reply_to and in_reply_to.startswith(ID)):
|
||||||
should_forward = False
|
should_forward = False
|
||||||
|
|
||||||
elif activity.has_type(ap.ActivityType.DELETE):
|
elif activity.has_type(ap.ActivityType.DELETE):
|
||||||
|
|
Loading…
Reference in a new issue