From 151ced0b417de415f2ce73fdfe5c456b14c41dea Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 1 Sep 2019 21:49:36 +0200 Subject: [PATCH] Fix queries for index/outbox --- app.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 33f0847..194d492 100644 --- a/app.py +++ b/app.py @@ -109,9 +109,14 @@ else: def inject_config(): q = { **in_outbox(), - **by_type([ActivityType.CREATE, ActivityType.ANNOUNCE]), - **not_deleted(), - **by_visibility(ap.Visibility.PUBLIC), + "$or": [ + { + **by_type(ActivityType.CREATE), + **not_deleted(), + **by_visibility(ap.Visibility.PUBLIC), + }, + {**by_type(ActivityType.ANNOUNCE), **not_undo()}, + ], } notes_count = DB.activities.count(q) # FIXME(tsileo): rename to all_count, and remove poll answers from it @@ -348,10 +353,15 @@ def index(): q = { **in_outbox(), - **by_type([ActivityType.CREATE, ActivityType.ANNOUNCE]), - **not_deleted(), - **by_visibility(ap.Visibility.PUBLIC), - "$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}], + "$or": [ + { + **by_type(ActivityType.CREATE), + **not_deleted(), + **by_visibility(ap.Visibility.PUBLIC), + "$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}], + }, + {**by_type(ActivityType.ANNOUNCE), **not_undo()}, + ], } apinned = [] @@ -478,9 +488,14 @@ def outbox(): # TODO(tsileo): returns the whole outbox if authenticated and look at OCAP support q = { **in_outbox(), - **by_type([ActivityType.CREATE, ActivityType.ANNOUNCE]), - **not_deleted(), - **by_visibility(ap.Visibility.PUBLIC), + "$or": [ + { + **by_type(ActivityType.CREATE), + **not_deleted(), + **by_visibility(ap.Visibility.PUBLIC), + }, + {**by_type(ActivityType.ANNOUNCE), **not_undo()}, + ], } return activitypubify( **activitypub.build_ordered_collection(