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.
This commit is contained in:
Thomas Sileo 2019-07-12 00:16:51 +02:00
parent 9e1bd06879
commit 5b76fe65aa

12
app.py
View file

@ -1727,12 +1727,14 @@ def api_bookmark():
undo = _user_api_arg("undo", default=None) == "yes" undo = _user_api_arg("undo", default=None) == "yes"
DB.activities.update_one( # Try to bookmark the `Create` first
{"meta.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}} if not DB.activities.update_one(
)
DB.activities.update_one(
{"activity.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}} {"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() return _user_api_response()