From 8e977a2b149928e3fa01ced6ad7c388464df6c2a Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Mon, 15 Jul 2019 23:08:12 +0200 Subject: [PATCH] More work on post visibility --- activitypub.py | 8 ++++++-- app.py | 17 +++++++++++++++++ migrations.py | 3 ++- sass/base_theme.scss | 19 ++++++++++--------- templates/index.html | 2 +- templates/layout.html | 2 +- templates/liked.html | 2 +- templates/stream.html | 6 +++--- templates/utils.html | 38 ++++++++++++++++++-------------------- 9 files changed, 59 insertions(+), 38 deletions(-) diff --git a/activitypub.py b/activitypub.py index 82a259d..b49b12a 100644 --- a/activitypub.py +++ b/activitypub.py @@ -124,6 +124,9 @@ class MicroblogPubBackend(Backend): object_id = activity.get_object_id() except ValueError: pass + object_visibility = None + if object_id: + object_visibility = ap.get_visibility(activity.get_object()) actor_id = activity.get_actor().id @@ -141,6 +144,7 @@ class MicroblogPubBackend(Backend): "visibility": visibility.name, "actor_id": actor_id, "object_id": object_id, + "object_visibility": object_visibility.name, "poll_answer": False, }, } @@ -670,7 +674,7 @@ def gen_feed(): fg.logo(ME.get("icon", {}).get("url")) fg.language("en") for item in DB.activities.find( - {"box": Box.OUTBOX.value, "type": "Create", "meta.deleted": False}, limit=10 + {"box": Box.OUTBOX.value, "type": "Create", "meta.deleted": False, "meta.public": True}, limit=10 ).sort("_id", -1): fe = fg.add_entry() fe.id(item["activity"]["object"].get("url")) @@ -684,7 +688,7 @@ def json_feed(path: str) -> Dict[str, Any]: """JSON Feed (https://jsonfeed.org/) document.""" data = [] for item in DB.activities.find( - {"box": Box.OUTBOX.value, "type": "Create", "meta.deleted": False}, limit=10 + {"box": Box.OUTBOX.value, "type": "Create", "meta.deleted": False, "meta.public": True}, limit=10 ).sort("_id", -1): data.append( { diff --git a/app.py b/app.py index 60ea41a..1116054 100644 --- a/app.py +++ b/app.py @@ -247,6 +247,16 @@ def _get_file_url(url, size, kind): return url +@app.template_filter() +def visibility(v: str) -> str: + return ap.Visibility[v].value.lower() + + +@app.template_filter() +def visibility_is_public(v: str) -> bool: + return v in [ap.Visibility.PUBLIC.name, ap.Visibility.UNLISTED.name] + + @app.template_filter() def emojify(text): return emoji_unicode.replace( @@ -1691,6 +1701,10 @@ def api_delete(): def api_boost(): note = _user_api_get_note() + # Ensures the note visibility allow us to build an Announce (in respect to the post visibility) + if ap.get_visibility(note) not in [ap.Visibility.PUBLIC, ap.VISIBILITY.UNLISTED]: + abort(400) + announce = note.build_announce(MY_PERSON) announce_id = post_to_outbox(announce) @@ -1841,6 +1855,7 @@ def admin_bookmarks(): @app.route("/inbox", methods=["GET", "POST"]) # noqa: C901 def inbox(): + # GET /inbox if request.method == "GET": if not is_api_request(): abort(404) @@ -1859,6 +1874,7 @@ def inbox(): ) ) + # POST/ inbox try: data = request.get_json(force=True) except Exception: @@ -3125,6 +3141,7 @@ def task_fetch_remote_question(): } ) remote_question = get_backend().fetch_iri(iri, no_cache=True) + # FIXME(tsileo): compute and set `meta.object_visiblity` (also update utils.py to do it) if ( local_question and ( diff --git a/migrations.py b/migrations.py index e9ef95a..4ce230c 100644 --- a/migrations.py +++ b/migrations.py @@ -104,4 +104,5 @@ class _1_MetaMigrationt(Migration): set_meta["meta.server"] = urlparse(data["remote_id"]).netloc logger.info(f"meta={set_meta}\n") - DB.activities.update_one({"_id": data["_id"]}, {"$set": set_meta}) + if set_meta: + DB.activities.update_one({"_id": data["_id"]}, {"$set": set_meta}) diff --git a/sass/base_theme.scss b/sass/base_theme.scss index 116f259..8b77b56 100644 --- a/sass/base_theme.scss +++ b/sass/base_theme.scss @@ -270,19 +270,20 @@ a:hover { float: left; border-radius:2px; } -.bar-icon { - background: $background-color; - padding: 5px; - color: $color-light; - margin-right: 10px; - float: left; - border: none; -} - .bar-item:hover { background: $primary-color; color: $background-color; } +.bar-item-no-border { + color: $color-light; + background: inherit; + cursor: default; +} +.bar-item-no-border:hover { + color: $color-light; + background: inherit; + cursor: default; +} button.bar-item { border: 0 } diff --git a/templates/index.html b/templates/index.html index f1c9711..527918d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -53,7 +53,7 @@ {% endif %} {% endif %} {% if item.meta.object %} - {{ utils.display_note(item.meta.object, ui=False, meta={'actor': item.meta.object_actor}) }} + {{ utils.display_note(item.meta.object, ui=False, meta=item.meta) }} {% endif %} {% elif item | has_type('Create') %} {{ utils.display_note(item.activity.object, meta=item.meta, no_color=True) }} diff --git a/templates/layout.html b/templates/layout.html index e97787d..65ff664 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -6,13 +6,13 @@ {% block title %}{{ config.NAME }}{% endblock %}'s microblog - {% if not request.args.get("older_than") and not request.args.get("previous_than") %}{% endif %} {% block links %}{% endblock %} {% if config.THEME_COLOR %}{% endif %}