From 5b76fe65aa5cb4cba0355f7c83603f793b54bfc4 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Fri, 12 Jul 2019 00:16:51 +0200 Subject: [PATCH] Prevent two activities from being bookmarked at once This could happen when bookmarking via an Announce when the original Create is also in the DB. --- app.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index fa18c66..886eda9 100644 --- a/app.py +++ b/app.py @@ -1727,12 +1727,14 @@ def api_bookmark(): undo = _user_api_arg("undo", default=None) == "yes" - DB.activities.update_one( - {"meta.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}} - ) - DB.activities.update_one( + # Try to bookmark the `Create` first + if not DB.activities.update_one( {"activity.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}} - ) + ).modified_count: + # Then look for the `Announce` + DB.activities.update_one( + {"meta.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}} + ) return _user_api_response()