From a5e0983ca8c6f1810b4d0da5d984d73c85682427 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 22 Jul 2018 22:22:30 +0200 Subject: [PATCH] Finish support for pinned/featured note --- app.py | 51 +++++++++++++++++++++++++++++++++++++++++--- sass/base_theme.scss | 16 +++++++++++++- templates/index.html | 10 +++++++++ templates/utils.html | 20 +++++++++++++++-- 4 files changed, 91 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 07bcdaa..7f226d5 100644 --- a/app.py +++ b/app.py @@ -803,14 +803,25 @@ def index(): "activity.object.inReplyTo": None, "meta.deleted": False, "meta.undo": False, + "$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}], } - outbox_data, older_than, newer_than = paginated_query(DB.activities, q) - + q_pinned = { + "box": Box.OUTBOX.value, + "type": ActivityType.CREATE.value, + "meta.deleted": False, + "meta.undo": False, + "meta.pinned": True, + } + pinned = list(DB.activities.find(q_pinned)) + outbox_data, older_than, newer_than = paginated_query( + DB.activities, q, limit=25 - len(pinned) + ) return render_template( "index.html", outbox_data=outbox_data, older_than=older_than, newer_than=newer_than, + pinned=pinned, ) @@ -1453,6 +1464,32 @@ def api_like(): return _user_api_response(activity=like.id) +@app.route("/api/note/pin", methods=["POST"]) +@api_required +def api_pin(): + note = _user_api_get_note(from_outbox=True) + + DB.activities.update_one( + {"activity.object.id": note.id, "box": Box.OUTBOX.value}, + {"$set": {"meta.pinned": True}}, + ) + + return _user_api_response(pinned=True) + + +@app.route("/api/note/unpin", methods=["POST"]) +@api_required +def api_unpin(): + note = _user_api_get_note(from_outbox=True) + + DB.activities.update_one( + {"activity.object.id": note.id, "box": Box.OUTBOX.value}, + {"$set": {"meta.pinned": False}}, + ) + + return _user_api_response(pinned=False) + + @app.route("/api/undo", methods=["POST"]) @api_required def api_undo(): @@ -1783,7 +1820,15 @@ def tags(tag): def featured(): if not is_api_request(): abort(404) - return jsonify(**activitypub.simple_build_ordered_collection("featured", [])) + q = { + "box": Box.OUTBOX.value, + "type": ActivityType.CREATE.value, + "meta.deleted": False, + "meta.undo": False, + "meta.pinned": True, + } + data = [clean_activity(doc["activity"]["object"]) for doc in DB.activities.find(q)] + return jsonify(**activitypub.simple_build_ordered_collection("featured", data)) @app.route("/liked") diff --git a/sass/base_theme.scss b/sass/base_theme.scss index e7b5b71..85447cd 100644 --- a/sass/base_theme.scss +++ b/sass/base_theme.scss @@ -237,13 +237,27 @@ a:hover { .og-link { text-decoration: none; } .og-link:hover { text-decoration: none; } .bar-item-no-hover { + cursor: default; background: $color-menu-background; padding: 5px; color: $color-light; margin-right:5px; border-radius:2px; } - +.bar-item-no-hover:hover { + cursor: default; +} +.bar-item-pinned { + cursor: default; + background: $color-menu-background; + color: $color-light; + padding: 5px; + margin-right:5px; + border-radius:2px; +} +.bar-item-pinned:hover { + cursor: default; +} .bar-item { background: $color-menu-background; padding: 5px; diff --git a/templates/index.html b/templates/index.html index 55e64a5..1331a1f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,6 +21,16 @@ {% include "header.html" %}
+ {% for item in pinned %} + {% if item.meta.pinned %} +

+ pinned +

+ {% endif %} + + {{ utils.display_note(item.activity.object, meta=item.meta, no_color=True) }} + {% endfor %} + {% for item in outbox_data %} {% if item | has_type('Announce') %} diff --git a/templates/utils.html b/templates/utils.html index c428fe6..ebf5f23 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -105,8 +105,8 @@ {% elif meta.count_reply and session.logged_in %} {{ meta.count_reply }} replies{% endif %} -{% if meta.count_boost and obj.id | is_from_outbox %}{{ meta.count_boost }} boosts{% endif %} -{% if meta.count_like and obj.id | is_from_outbox %}{{ meta.count_like }} likes{% endif %} +{% if not perma and meta.count_boost and obj.id | is_from_outbox %}{{ meta.count_boost }} boosts{% endif %} +{% if not perma and meta.count_like and obj.id | is_from_outbox %}{{ meta.count_like }} likes{% endif %} {% if session.logged_in %} {% if ui%} @@ -153,6 +153,22 @@ +{% if meta.pinned %} +
+ + + + +
+{% else %} +
+ + + + +
+{% endif %} + {% else %}