From 612656d75b555bdf90c39a34beb0cba49353f258 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 17 Aug 2019 09:56:46 +0200 Subject: [PATCH] Fix published query, and improve announce dedup --- core/meta.py | 9 +++++++-- core/notifications.py | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/meta.py b/core/meta.py index 34b694e..2b51346 100644 --- a/core/meta.py +++ b/core/meta.py @@ -3,6 +3,8 @@ from enum import Enum from enum import unique from typing import Any from typing import Dict +from typing import List +from typing import Union from little_boxes import activitypub as ap @@ -66,7 +68,10 @@ def in_outbox() -> _SubQuery: return {"box": Box.OUTBOX.value} -def by_type(type_: ap.ActivityType) -> _SubQuery: +def by_type(type_: Union[ap.ActivityType, List[ap.ActivityType]]) -> _SubQuery: + if isinstance(type_, list): + return {"type": {"$in": [t.value for t in type_]}} + return {"type": type_.value} @@ -104,4 +109,4 @@ def upsert(data: Dict[MetaKey, Any]) -> _SubQuery: def published_after(dt: datetime) -> _SubQuery: - return flag(MetaKey.PUBLISHED, {"gt": ap.format_datetime(dt)}) + return flag(MetaKey.PUBLISHED, {"$gt": ap.format_datetime(dt)}) diff --git a/core/notifications.py b/core/notifications.py index 614b090..002f6b4 100644 --- a/core/notifications.py +++ b/core/notifications.py @@ -143,6 +143,7 @@ def _announce_set_inbox_flags(activity: ap.Announce, new_meta: _NewMeta) -> None if not find_one_activity( { **in_inbox(), + **by_type([ap.ActivityType.CRETATE, ap.ActivityType.ANNOUNCE]), **by_object_id(obj.id), **flag(MetaKey.STREAM, True), **published_after(datetime.now(timezone.utc) - timedelta(hours=12)),