mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
Fix reply counter
This commit is contained in:
parent
7bd2aa4592
commit
852ffc00c6
3 changed files with 19 additions and 9 deletions
|
@ -548,6 +548,12 @@ def task_process_reply() -> _Response:
|
|||
if not find_one_activity(by_object_id(root_reply)):
|
||||
return ""
|
||||
|
||||
# In case the activity was from the inbox
|
||||
update_one_activity(
|
||||
{**by_object_id(activity.id), **by_type(ap.ActivityType.CREATE)},
|
||||
upsert({MetaKey.THREAD_ROOT_PARENT: root_reply}),
|
||||
)
|
||||
|
||||
for new_reply in new_replies:
|
||||
if find_one_activity(by_object_id(new_reply.id)) or DB.replies.find_one(
|
||||
{"remote_id": root_reply}
|
||||
|
@ -558,7 +564,7 @@ def task_process_reply() -> _Response:
|
|||
save_reply(
|
||||
new_reply,
|
||||
{
|
||||
"meta.thread_root_parent": root_reply,
|
||||
**flag(MetaKey.THREAD_ROOT_PARENT, root_reply),
|
||||
**flag(MetaKey.ACTOR, actor.to_dict(embed=True)),
|
||||
**flag(MetaKey.ACTOR_HASH, _actor_hash(actor)),
|
||||
},
|
||||
|
|
|
@ -511,10 +511,11 @@ class MicroblogPubBackend(Backend):
|
|||
)
|
||||
if not creply:
|
||||
# Maybe it's the reply of a reply?
|
||||
if not DB.replies.find_one_and_update(
|
||||
DB.replies.find_one_and_update(
|
||||
by_remote_id(in_reply_to), inc(MetaKey.COUNT_REPLY, 1)
|
||||
):
|
||||
# We don't have the reply stored, spawn a task to process it (and determine if it needs to be saved)
|
||||
)
|
||||
|
||||
# Spawn a task to process it (and determine if it needs to be saved)
|
||||
Tasks.process_reply(create.get_object().id)
|
||||
|
||||
|
||||
|
@ -643,20 +644,22 @@ def _add_answers_to_question(raw_doc: Dict[str, Any]) -> None:
|
|||
|
||||
|
||||
def add_extra_collection(raw_doc: Dict[str, Any]) -> Dict[str, Any]:
|
||||
if raw_doc["activity"]["type"] != ap.ActivityType.CREATE.value:
|
||||
if not ap._has_type(raw_doc["activity"]["type"], ap.ActivityType.CREATE.value):
|
||||
return raw_doc
|
||||
|
||||
raw_doc["activity"]["object"]["replies"] = embed_collection(
|
||||
raw_doc.get("meta", {}).get("count_direct_reply", 0),
|
||||
raw_doc.get("meta", {}).get(MetaKey.COUNT_REPLY.value, 0),
|
||||
f'{raw_doc["remote_id"]}/replies',
|
||||
)
|
||||
|
||||
raw_doc["activity"]["object"]["likes"] = embed_collection(
|
||||
raw_doc.get("meta", {}).get("count_like", 0), f'{raw_doc["remote_id"]}/likes'
|
||||
raw_doc.get("meta", {}).get(MetaKey.COUNT_LIKE.value, 0),
|
||||
f'{raw_doc["remote_id"]}/likes',
|
||||
)
|
||||
|
||||
raw_doc["activity"]["object"]["shares"] = embed_collection(
|
||||
raw_doc.get("meta", {}).get("count_boost", 0), f'{raw_doc["remote_id"]}/shares'
|
||||
raw_doc.get("meta", {}).get(MetaKey.COUNT_BOOST.value, 0),
|
||||
f'{raw_doc["remote_id"]}/shares',
|
||||
)
|
||||
|
||||
return raw_doc
|
||||
|
|
|
@ -35,6 +35,7 @@ class MetaKey(Enum):
|
|||
OBJECT_ACTOR_ID = "object_actor_id"
|
||||
OBJECT_ACTOR_HASH = "object_actor_hash"
|
||||
PUBLIC = "public"
|
||||
THREAD_ROOT_PARENT = "thread_root_parent"
|
||||
|
||||
DELETED = "deleted"
|
||||
BOOSTED = "boosted"
|
||||
|
|
Loading…
Reference in a new issue