From fe4ea02cb062b31854a426d987298fe2d4f8bef7 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Mon, 22 Jul 2019 20:32:35 +0200 Subject: [PATCH] Lists support (draft) --- app.py | 104 +++++++++++++++++++++++++++++++++++++++ templates/following.html | 30 ++++++++++- templates/layout.html | 1 + templates/lists.html | 61 +++++++++++++++++++++++ 4 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 templates/lists.html diff --git a/app.py b/app.py index 43bc968..8dd51fc 100644 --- a/app.py +++ b/app.py @@ -1578,6 +1578,14 @@ def admin_new(): ) +@app.route("/admin/lists", methods=["GET"]) +@login_required +def admin_lists(): + lists = list(DB.lists.find()) + + return render_template("lists.html", lists=lists) + + @app.route("/admin/notifications") @login_required def admin_notifications(): @@ -1895,6 +1903,34 @@ def admin_stream(): ) +@app.route("/admin/list/") +@login_required +def admin_list(name): + list_ = DB.lists.find_one({"name": name}) + if not list_: + abort(404) + + q = { + "meta.stream": True, + "meta.deleted": False, + "meta.actor_id": {"$in": list_["members"]}, + } + + 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("/admin/bookmarks") @login_required def admin_bookmarks(): @@ -2073,6 +2109,72 @@ def api_debug(): ) +@app.route("/api/new_list", methods=["POST"]) +@api_required +def api_new_list(): + name = _user_api_arg("name") + if not name: + raise ValueError("missing name") + + if not DB.lists.find_one({"name": name}): + DB.lists.insert_one({"name": name, "members": []}) + + return _user_api_response(name=name) + + +@app.route("/api/delete_list", methods=["POST"]) +@api_required +def api_delete_list(): + name = _user_api_arg("name") + if not name: + raise ValueError("missing name") + + if not DB.lists.find_one({"name": name}): + abort(404) + + DB.lists.delete_one({"name": name}) + + return _user_api_response() + + +@app.route("/api/add_to_list", methods=["POST"]) +@api_required +def api_add_to_list(): + list_name = _user_api_arg("list_name") + if not list_name: + raise ValueError("missing list_name") + + if not DB.lists.find_one({"name": list_name}): + raise ValueError(f"list {list_name} does not exist") + + actor_id = _user_api_arg("actor_id") + if not actor_id: + raise ValueError("missing actor_id") + + DB.lists.update_one({"name": list_name}, {"$addToSet": {"members": actor_id}}) + + return _user_api_response() + + +@app.route("/api/remove_from_list", methods=["POST"]) +@api_required +def api_remove_from_list(): + list_name = _user_api_arg("list_name") + if not list_name: + raise ValueError("missing list_name") + + if not DB.lists.find_one({"name": list_name}): + raise ValueError(f"list {list_name} does not exist") + + actor_id = _user_api_arg("actor_id") + if not actor_id: + raise ValueError("missing actor_id") + + DB.lists.update_one({"name": list_name}, {"$pull": {"members": actor_id}}) + + return _user_api_response() + + @app.route("/api/new_note", methods=["POST"]) @api_required def api_new_note(): @@ -2322,11 +2424,13 @@ def following(): for doc in following if "remote_id" in doc and "object" in doc.get("meta", {}) ] + lists = list(DB.lists.find()) return render_template( "following.html", following_data=following, older_than=older_than, newer_than=newer_than, + lists=lists, ) diff --git a/templates/following.html b/templates/following.html index c850f88..16c713f 100644 --- a/templates/following.html +++ b/templates/following.html @@ -11,12 +11,40 @@ {% for (follow_id, follow) in following_data %} {% if session.logged_in %}
-
+
+
+ + + + + +
+ +{% for l in lists %} +{% if follow.id in l.members %} +
+ + + + +
+ + +{% endif %} +{% endfor %} +
{% endif %} diff --git a/templates/layout.html b/templates/layout.html index 284256f..502b083 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -28,6 +28,7 @@
  • New
  • Stream
  • Notifications
  • +
  • Lists
  • Bookmarks
  • Lookup
  • Logout
  • diff --git a/templates/lists.html b/templates/lists.html new file mode 100644 index 0000000..43c5b66 --- /dev/null +++ b/templates/lists.html @@ -0,0 +1,61 @@ +{% extends "layout.html" %} +{% import 'utils.html' as utils %} +{% block title %}Lists - {{ config.NAME }}{% endblock %} +{% block headers %} + +{% endblock %} +{% block content %} +
    +{% include "header.html" %} + +
    +

    New List

    +
    + + + + +
    + +

    Lists

    +

    Manage list members in the Following section

    + + + +

    Manage lists

    +{% for l in lists %} +

    {{ l.name }} {{ l.members | length }} members

    +
    + + + + +
    + +
    + +{% for member in l.members %} +
    +
    + + + + + +
    +
    + +
    + {{ utils.display_actor_inline(member | get_actor, size=80) }} +
    +{% endfor %} + +{% endfor %} +
    +
    +
    +{% endblock %}