From 737949e197698d2db70dcd8324ee75a4662ee705 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 10 Jul 2019 23:32:48 +0200 Subject: [PATCH] Add boomarks feature/admin section --- app.py | 45 ++++++++++++++++++++++++++++++++++++++++--- templates/layout.html | 2 +- templates/utils.html | 18 +++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index ed9a986..fa18c66 100644 --- a/app.py +++ b/app.py @@ -171,15 +171,17 @@ def inject_config(): "meta.undo": False, } + logged_in = session.get("logged_in", False) + return dict( microblogpub_version=VERSION, config=config, - logged_in=session.get("logged_in", False), + logged_in=logged_in, followers_count=DB.activities.count(followers_q), - following_count=DB.activities.count(following_q), + following_count=DB.activities.count(following_q) if logged_in else 0, notes_count=notes_count, liked_count=liked_count, - with_replies_count=with_replies_count, + with_replies_count=with_replies_count if logged_in else 0, me=ME, base_url=config.BASE_URL, ) @@ -1718,6 +1720,23 @@ def api_like(): return _user_api_response(activity=like_id) +@app.route("/api/bookmark", methods=["POST"]) +@api_required +def api_bookmark(): + note = _user_api_get_note() + + 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( + {"activity.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}} + ) + + return _user_api_response() + + @app.route("/api/note/pin", methods=["POST"]) @api_required def api_pin(): @@ -1785,6 +1804,26 @@ def admin_stream(): ) +@app.route("/admin/bookmarks") +@login_required +def admin_bookmarks(): + q = {"meta.bookmarked": True} + + tpl = "stream.html" + if request.args.get("debug"): + tpl = "stream_debug.html" + if request.args.get("debug_inbox"): + q = {} + + inbox_data, older_than, newer_than = paginated_query( + DB.activities, q, limit=int(request.args.get("limit", 25)) + ) + + return render_template( + tpl, inbox_data=inbox_data, older_than=older_than, newer_than=newer_than + ) + + @app.route("/inbox", methods=["GET", "POST"]) # noqa: C901 def inbox(): if request.method == "GET": diff --git a/templates/layout.html b/templates/layout.html index d805007..2e40ea6 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -26,8 +26,8 @@
  • Public
  • New
  • Stream
  • +
  • Bookmarks
  • Notifications
  • -
  • Following
  • Lookup
  • Logout
  • diff --git a/templates/utils.html b/templates/utils.html index 0c95326..a63895e 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -212,6 +212,24 @@ {% endif %} +{% if meta.bookmarked or request.path == url_for("admin_bookmarks") %} +
    + + + + + +
    +{% else %} +
    + + + + +
    +{% endif %} + + {% endif %} {% if obj.id | is_from_outbox %}