From c100796c8617659e33af3a369b71226c1d776122 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 10 Apr 2019 22:50:36 +0200 Subject: [PATCH] Emojis \o/ and fix threads --- activitypub.py | 1 + app.py | 28 ++++++++++++++-------------- config.py | 7 +++++++ templates/layout.html | 16 +++++++++++++++- templates/new.html | 36 ++++++++++++++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/activitypub.py b/activitypub.py index 9185745..4f7104a 100644 --- a/activitypub.py +++ b/activitypub.py @@ -473,6 +473,7 @@ class MicroblogPubBackend(Backend): # It means the activity is not in the inbox, and not in the outbox, we want to save it self.save(Box.REPLIES, reply) new_threads.append(reply.id) + # TODO(tsileo): parses the replies collection and import the replies? while reply is not None: in_reply_to = reply.inReplyTo diff --git a/app.py b/app.py index 13f5495..debe25c 100644 --- a/app.py +++ b/app.py @@ -72,6 +72,7 @@ from config import BASE_URL from config import DB from config import DEBUG_MODE from config import DOMAIN +from config import EMOJIS from config import HEADERS from config import ICON_URL from config import ID @@ -91,6 +92,7 @@ from poussetaches import PousseTaches phost = "http://" + os.getenv("COMPOSE_PROJECT_NAME", "") p = PousseTaches(f"{phost}_poussetaches_1:7991", f"{phost}_web_1:5005") +# p = PousseTaches("http://localhost:7991", "http://localhost:5000") back = activitypub.MicroblogPubBackend() ap.use_backend(back) @@ -831,25 +833,22 @@ def with_replies(): ) -def _build_thread(data, include_children=True): +def _build_thread(data, include_children=True): # noqa: C901 data["_requested"] = True - print(data) root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"]) query = { - "$or": [ - {"meta.thread_root_parent": root_id, "type": "Create"}, - {"activity.object.id": root_id}, - ] + "meta.thread_root_parent": root_id, + "meta.deleted": False, } - if data["activity"]["object"].get("inReplyTo"): - query["$or"].append( - {"activity.object.id": data["activity"]["object"]["inReplyTo"]} - ) - - # Fetch the root replies, and the children - replies = [data] + list(DB.activities.find(query)) + replies = [data] + for dat in DB.activities.find(query): + if dat["type"][0] != ActivityType.CREATE.value: + # Make a Note/Question/... looks like a Create + dat = {"activity": {"object": dat["activity"]}, "meta": dat["meta"], "_id": dat["_id"]} + replies.append(dat) replies = sorted(replies, key=lambda d: d["activity"]["object"]["published"]) + # Index all the IDs in order to build a tree idx = {} replies2 = [] @@ -1326,6 +1325,7 @@ def admin_lookup(): ) print(data) + app.logger.debug(data.to_dict()) return render_template( "lookup.html", data=data, meta=meta, url=request.form.get("url") ) @@ -1383,7 +1383,7 @@ def admin_new(): content = f"@{actor.preferredUsername}@{domain} " thread = _build_thread(data) - return render_template("new.html", reply=reply_id, content=content, thread=thread) + return render_template("new.html", reply=reply_id, content=content, thread=thread, emojis=EMOJIS.split(" ")) @app.route("/admin/notifications") diff --git a/config.py b/config.py index 3be15f2..074c098 100644 --- a/config.py +++ b/config.py @@ -106,6 +106,10 @@ def create_indexes(): DB.command("compact", "activities") DB.activities.create_index([("remote_id", pymongo.ASCENDING)]) DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)]) + DB.activities.create_index([("meta.thread_root_parent", pymongo.ASCENDING)]) + DB.activities.create_index( + [("meta.thread_root_parent", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)] + ) DB.activities.create_index( [("activity.object.id", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)] ) @@ -195,3 +199,6 @@ ME = { }, "publicKey": KEY.to_dict(), } + +# TODO(tsileo): read the config from the YAML if set +EMOJIS = "😺 😸 😹 😻 😼 😽 🙀 😿 😾 😺 😸 😹 😻 😼 😽 🙀 😿 😾" diff --git a/templates/layout.html b/templates/layout.html index fb7d6d2..eab7301 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -11,7 +11,11 @@ {% if not request.args.get("older_than") and not request.args.get("previous_than") %}{% endif %} {% block links %}{% endblock %} {% if config.THEME_COLOR %}{% endif %} - + {% block headers %}{% endblock %} @@ -39,5 +43,15 @@ Powered by microblog.pub {{ microblogpub_version }} (source code) and the ActivityPub protocol + + diff --git a/templates/new.html b/templates/new.html index a14bec7..04e34f6 100644 --- a/templates/new.html +++ b/templates/new.html @@ -1,6 +1,9 @@ {% extends "layout.html" %} {% import 'utils.html' as utils %} {% block title %}New - {{ config.NAME }}{% endblock %} +{% block headers %} + +{% endblock %} {% block content %}
{% include "header.html" %} @@ -15,7 +18,14 @@ {% if reply %}{% endif %} - + +

+{% for emoji in emojis %} +{{ emoji }} +{% endfor %} +

+ +
@@ -24,4 +34,26 @@
-{% endblock %} +{% endblock %}