From 468f17936f0b7dcec5990f90d66a518674ba3fc3 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 18 Aug 2019 09:40:43 +0200 Subject: [PATCH] Fix reply counters --- core/activitypub.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/activitypub.py b/core/activitypub.py index 3f5e908..9c172c2 100644 --- a/core/activitypub.py +++ b/core/activitypub.py @@ -166,8 +166,13 @@ def post_to_inbox(activity: ap.BaseActivity) -> None: actor.has_type(ap.ActivityType.APPLICATION) and actor.id.endswith("/relay") and activity.has_type(ap.ActivityType.ANNOUNCE) - and not find_one_activity(by_object_id(activity.get_object_id())) - and not DB.replies.find_one({"remote_id": activity.id}) + and not find_one_activity( + { + **by_object_id(activity.get_object_id()), + **by_type(ap.ActivityType.CREATE), + } + ) + and not DB.replies.find_one(by_remote_id(activity.get_object_id())) ): Tasks.process_reply(activity.get_object_id()) return @@ -716,6 +721,15 @@ def update_cached_actor(actor: ap.BaseActivity) -> None: } ), ) + DB.replies.update_many( + { + **flag(MetaKey.ACTOR_ID, actor.id), + **flag(MetaKey.ACTOR_HASH, {"$ne": actor_hash}), + }, + upsert( + {MetaKey.ACTOR: actor.to_dict(embed=True), MetaKey.ACTOR_HASH: actor_hash} + ), + ) # TODO(tsileo): Also update following (it's in the object) # DB.activities.update_many( # {"meta.object_id": actor.id}, {"$set": {"meta.object": actor.to_dict(embed=True)}}