From 6ab59d2e41de315f6376897c7dfeb2cd3f740c66 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 13 Jul 2019 00:28:14 +0200 Subject: [PATCH 1/9] Start working on post visibility --- app.py | 30 +++++++++++++++++++++++++----- templates/new.html | 5 +++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 93c54ea..840c1c0 100644 --- a/app.py +++ b/app.py @@ -1532,6 +1532,7 @@ def admin_new(): reply=reply_id, content=content, thread=thread, + visibility=ap.Visibility, emojis=EMOJIS.split(" "), ) @@ -1995,22 +1996,41 @@ def api_new_note(): except ValueError: pass + visibility = ap.Visibility[ + _user_api_arg("visibility", default=ap.Visibility.PUBLIC.name) + ] + content, tags = parse_markdown(source) - to = request.args.get("to") - cc = [ID + "/followers"] + + to, cc = [], [] + if visibility == ap.Visibility.PUBLIC: + to = [ap.AS_PUBLIC] + cc = [ID + "/followers"] + elif visibility == ap.Visibility.UNLISTED: + to = [ID + "/followers"] + cc = [ap.AS_PUBLIC] + elif visibility == ap.Visibility.FOLLOWERS_ONLY: + to = [ID + "/followers"] + cc = [] if _reply: reply = ap.fetch_remote_activity(_reply) - cc.append(reply.attributedTo) + if visibility == ap.Visibility.DIRECT: + to.append(reply.attributedTo) + else: + cc.append(reply.attributedTo) for tag in tags: if tag["type"] == "Mention": - cc.append(tag["href"]) + if visibility == ap.Visibility.DIRECT: + to.append(tag["href"]) + else: + cc.append(tag["href"]) raw_note = dict( attributedTo=MY_PERSON.id, cc=list(set(cc)), - to=[to if to else ap.AS_PUBLIC], + to=list(set(to)), content=content, tag=tags, source={"mediaType": "text/markdown", "content": source}, diff --git a/templates/new.html b/templates/new.html index 9b27df6..0fa98fc 100644 --- a/templates/new.html +++ b/templates/new.html @@ -21,6 +21,11 @@
+ {% if reply %}{% endif %}

From 152bcf2b26d71f1cc6f7844575a60c374f538dbb Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 13 Jul 2019 00:38:51 +0200 Subject: [PATCH 2/9] Only show public stuff on the homepage --- app.py | 11 ++++++----- tasks.py | 2 +- templates/header.html | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 840c1c0..5468f59 100644 --- a/app.py +++ b/app.py @@ -86,8 +86,8 @@ from config import VERSION_DATE from config import _drop_db from poussetaches import PousseTaches from tasks import Tasks -from utils import parse_datetime from utils import opengraph +from utils import parse_datetime from utils.key import get_secret_key from utils.lookup import lookup from utils.media import Kind @@ -143,13 +143,13 @@ def inject_config(): notes_count = DB.activities.find( {"box": Box.OUTBOX.value, "$or": [q, {"type": "Announce", "meta.undo": False}]} ).count() + # FIXME(tsileo): rename to all_count, and remove poll answers from it with_replies_count = DB.activities.find( { "box": Box.OUTBOX.value, "type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]}, "meta.undo": False, "meta.deleted": False, - "meta.public": True, } ).count() liked_count = DB.activities.count( @@ -875,6 +875,7 @@ def index(): "activity.object.inReplyTo": None, "meta.deleted": False, "meta.undo": False, + "meta.public": True, "$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}], } print(list(DB.activities.find(q))) @@ -887,6 +888,7 @@ def index(): "type": ActivityType.CREATE.value, "meta.deleted": False, "meta.undo": False, + "meta.public": True, "meta.pinned": True, } pinned = list(DB.activities.find(q_pinned)) @@ -906,14 +908,13 @@ def index(): return resp -@app.route("/with_replies") +@app.route("/all") @login_required -def with_replies(): +def all(): q = { "box": Box.OUTBOX.value, "type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]}, "meta.deleted": False, - "meta.public": True, "meta.undo": False, } outbox_data, older_than, newer_than = paginated_query(DB.activities, q) diff --git a/tasks.py b/tasks.py index 9855f64..9515fe0 100644 --- a/tasks.py +++ b/tasks.py @@ -2,8 +2,8 @@ import os from datetime import datetime from datetime import timezone -from utils import parse_datetime from poussetaches import PousseTaches +from utils import parse_datetime p = PousseTaches( os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"), diff --git a/templates/header.html b/templates/header.html index 8fc7eb1..29c396d 100644 --- a/templates/header.html +++ b/templates/header.html @@ -18,7 +18,7 @@