From afa33b4e7c4bbaf2e17beb73f7a97ad16879c68b Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Tue, 22 Oct 2019 20:32:12 +0200 Subject: [PATCH] Fix attachment display and tweak actor lookup --- blueprints/admin.py | 28 +++++++++++++++++++++++++++- templates/lookup.html | 16 ++++++++++++++++ utils/template_filters.py | 6 +++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/blueprints/admin.py b/blueprints/admin.py index 60dbc6c..ec9642d 100644 --- a/blueprints/admin.py +++ b/blueprints/admin.py @@ -191,11 +191,32 @@ def admin_tasks() -> _Response: def admin_lookup() -> _Response: data = None meta = None + follower = None + following = None if request.args.get("url"): data = lookup(request.args.get("url")) # type: ignore if data: if not data.has_type(ap.ACTOR_TYPES): meta = _meta(data) + else: + follower = find_one_activity( + { + "box": "inbox", + "type": ap.ActivityType.FOLLOW.value, + "meta.actor_id": data.id, + "meta.undo": False, + } + ) + following = find_one_activity( + { + **by_type(ap.ActivityType.FOLLOW), + **by_object_id(data.id), + **not_undo(), + **in_outbox(), + **follow_request_accepted(), + } + ) + if data.has_type(ap.ActivityType.QUESTION): p.push(data.id, "/task/fetch_remote_question") @@ -203,7 +224,12 @@ def admin_lookup() -> _Response: app.logger.debug(data.to_dict()) return htmlify( render_template( - "lookup.html", data=data, meta=meta, url=request.args.get("url") + "lookup.html", + data=data, + meta=meta, + follower=follower, + following=following, + url=request.args.get("url"), ) ) diff --git a/templates/lookup.html b/templates/lookup.html index 6790c10..fa740cc 100644 --- a/templates/lookup.html +++ b/templates/lookup.html @@ -17,6 +17,20 @@
{% if data | has_actor_type %}
+{% if following %} +
+ + + + +
+
+ + + + +
+{% else %} profile
@@ -24,6 +38,8 @@
+{% endif %} +{% if follower %}follows you!{% endif %}
diff --git a/utils/template_filters.py b/utils/template_filters.py index 440f88a..71f6cdc 100644 --- a/utils/template_filters.py +++ b/utils/template_filters.py @@ -273,9 +273,6 @@ _FILE_URL_CACHE = LRUCache(4096) def _get_file_url(url, size, kind) -> str: - if url.startswith(BASE_URL): - return url - k = (url, size, kind) cached = _FILE_URL_CACHE.get(k) if cached: @@ -288,6 +285,9 @@ def _get_file_url(url, size, kind) -> str: return out _logger.error(f"cache not available for {url}/{size}/{kind}") + if url.startswith(BASE_URL): + return url + p = urlparse(url) return f"/p/{p.scheme}" + p._replace(scheme="").geturl()[1:]