Fix reply counters

This commit is contained in:
Thomas Sileo 2019-08-18 09:40:43 +02:00
parent 480fc890de
commit 468f17936f

View file

@ -166,8 +166,13 @@ def post_to_inbox(activity: ap.BaseActivity) -> None:
actor.has_type(ap.ActivityType.APPLICATION) actor.has_type(ap.ActivityType.APPLICATION)
and actor.id.endswith("/relay") and actor.id.endswith("/relay")
and activity.has_type(ap.ActivityType.ANNOUNCE) and activity.has_type(ap.ActivityType.ANNOUNCE)
and not find_one_activity(by_object_id(activity.get_object_id())) and not find_one_activity(
and not DB.replies.find_one({"remote_id": activity.id}) {
**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()) Tasks.process_reply(activity.get_object_id())
return 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) # TODO(tsileo): Also update following (it's in the object)
# DB.activities.update_many( # DB.activities.update_many(
# {"meta.object_id": actor.id}, {"$set": {"meta.object": actor.to_dict(embed=True)}} # {"meta.object_id": actor.id}, {"$set": {"meta.object": actor.to_dict(embed=True)}}