From 4f1b51f7d5d577a2938569fb9ea182b10a443821 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 25 Jun 2022 10:20:07 +0200 Subject: [PATCH] UI improvements --- app/actor.py | 4 ++ app/ap_object.py | 8 +++ app/boxes.py | 10 ++++ app/main.py | 10 ---- app/models.py | 16 ++++++ app/scss/main.scss | 7 +++ app/templates.py | 13 +++++ app/templates/admin_inbox.html | 9 +--- app/templates/admin_outbox.html | 7 --- app/templates/admin_stream.html | 7 --- app/templates/followers.html | 2 +- app/templates/header.html | 4 +- app/templates/index.html | 2 - app/templates/object.html | 7 ++- app/templates/utils.html | 91 +++++++++++++++++++++++++++------ 15 files changed, 145 insertions(+), 52 deletions(-) diff --git a/app/actor.py b/app/actor.py index 7291a6b..805d466 100644 --- a/app/actor.py +++ b/app/actor.py @@ -47,6 +47,10 @@ class Actor: def preferred_username(self) -> str: return self.ap_actor["preferredUsername"] + @property + def display_name(self) -> str: + return self.name or self.preferred_username + @property def handle(self) -> str: return _handle(self.ap_actor) diff --git a/app/ap_object.py b/app/ap_object.py index 0051867..69796f2 100644 --- a/app/ap_object.py +++ b/app/ap_object.py @@ -19,6 +19,14 @@ class Object: def is_from_db(self) -> bool: return False + @property + def is_from_outbox(self) -> bool: + return False + + @property + def is_from_inbox(self) -> bool: + return False + @property def ap_type(self) -> str: return self.ap_object["type"] diff --git a/app/boxes.py b/app/boxes.py index 253791d..3da816e 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -237,6 +237,11 @@ def send_create( raise ValueError("Object has no context") context = in_reply_to_object.ap_context + if in_reply_to_object.is_from_outbox: + db.query(models.OutboxObject).filter( + models.OutboxObject.ap_id == in_reply_to, + ).update({"replies_count": models.OutboxObject.replies_count + 1}) + for (upload, filename) in uploads: attachments.append(upload_to_attachment(upload, filename)) @@ -501,6 +506,11 @@ def _handle_create_activity( logger.info(f"Invalid tags: {tags}") return None + if created_object.in_reply_to and created_object.in_reply_to.startswith(BASE_URL): + db.query(models.OutboxObject).filter( + models.OutboxObject.ap_id == created_object.in_reply_to, + ).update({"replies_count": models.OutboxObject.replies_count + 1}) + for tag in tags: if tag.get("name") == LOCAL_ACTOR.handle or tag.get("href") == LOCAL_ACTOR.url: notif = models.Notification( diff --git a/app/main.py b/app/main.py index c594303..7a8bad8 100644 --- a/app/main.py +++ b/app/main.py @@ -59,9 +59,6 @@ from app.uploads import UPLOAD_DIR # - inbox/outbox in the admin (as in show every objects) # - show likes/announces counter for outbox activities # - update actor support -# - replies support -# - file upload + place/exif extraction (or not) support -# - custom emoji support # - hash config/profile to detect when to send Update actor # # - [ ] block support @@ -72,13 +69,6 @@ from app.uploads import UPLOAD_DIR # - [ ] custom emoji # - [ ] poll/questions support # - [ ] cleanup tasks -# - notifs: -# - MENTIONED -# - LIKED -# - ANNOUNCED -# - FOLLOWED -# - UNFOLLOWED -# - POLL_ENDED app = FastAPI(docs_url=None, redoc_url=None) app.mount("/static", StaticFiles(directory="app/static"), name="static") diff --git a/app/models.py b/app/models.py index 991f046..c4aefb2 100644 --- a/app/models.py +++ b/app/models.py @@ -114,6 +114,14 @@ class InboxObject(Base, BaseObject): else: return None + @property + def is_from_db(self) -> bool: + return True + + @property + def is_from_inbox(self) -> bool: + return True + class OutboxObject(Base, BaseObject): __tablename__ = "outbox" @@ -221,6 +229,14 @@ class OutboxObject(Base, BaseObject): else: return None + @property + def is_from_db(self) -> bool: + return True + + @property + def is_from_outbox(self) -> bool: + return True + class Follower(Base): __tablename__ = "follower" diff --git a/app/scss/main.scss b/app/scss/main.scss index 8144b66..4eb6d29 100644 --- a/app/scss/main.scss +++ b/app/scss/main.scss @@ -133,3 +133,10 @@ nav.flexbox { } } } +.actor-action { + padding-left:70px; + margin-top:20px; + span { + float: right; + } +} diff --git a/app/templates.py b/app/templates.py index f77f4aa..d519ff2 100644 --- a/app/templates.py +++ b/app/templates.py @@ -183,8 +183,21 @@ def _has_media_type(attachment: Attachment, media_type_prefix: str) -> bool: return attachment.media_type.startswith(media_type_prefix) +def _format_date(dt: datetime) -> str: + return dt.strftime("%b %d, %Y, %H:%M") + + +def _pluralize(count: int, singular: str = "", plural: str = "s") -> str: + if count > 1: + return plural + else: + return singular + + _templates.env.filters["domain"] = _filter_domain _templates.env.filters["media_proxy_url"] = _media_proxy_url _templates.env.filters["clean_html"] = _clean_html _templates.env.filters["timeago"] = _timeago +_templates.env.filters["format_date"] = _format_date _templates.env.filters["has_media_type"] = _has_media_type +_templates.env.filters["pluralize"] = _pluralize diff --git a/app/templates/admin_inbox.html b/app/templates/admin_inbox.html index 575ee2f..8d02445 100644 --- a/app/templates/admin_inbox.html +++ b/app/templates/admin_inbox.html @@ -7,13 +7,8 @@ {{ utils.display_object(inbox_object.relates_to_anybox_object) }} {% elif inbox_object.ap_type in ["Article", "Note", "Video"] %} {{ utils.display_object(inbox_object) }} - {% if inbox_object.liked_via_outbox_object_ap_id %} - {{ utils.admin_undo_button(inbox_object.liked_via_outbox_object_ap_id, "Unlike") }} - {% else %} - {{ utils.admin_like_button(inbox_object.ap_id) }} - {% endif %} - {{ utils.admin_announce_button(inbox_object.ap_id) }} - {{ utils.admin_reply_button(inbox_object.ap_id) }} +{% elif inbox_object.ap_type == "Follow" %} + {{ utils.display_object(inbox_object) }} {% else %} Implement {{ inbox_object.ap_type }} {% endif %} diff --git a/app/templates/admin_outbox.html b/app/templates/admin_outbox.html index 6154d2a..c2b4a08 100644 --- a/app/templates/admin_outbox.html +++ b/app/templates/admin_outbox.html @@ -8,13 +8,6 @@ {{ utils.display_object(outbox_object.relates_to_anybox_object) }} {% elif outbox_object.ap_type in ["Article", "Note", "Video"] %} {{ utils.display_object(outbox_object) }} - {% if outbox_object.liked_via_outbox_object_ap_id %} - {{ utils.admin_undo_button(outbox_object.liked_via_outbox_object_ap_id, "Unlike") }} - {% else %} - {{ utils.admin_like_button(outbox_object.ap_id) }} - {% endif %} - {{ utils.admin_announce_button(outbox_object.ap_id) }} - {{ utils.admin_reply_button(outbox_object.ap_id) }} {% else %} Implement {{ outbox_object.ap_type }} {% endif %} diff --git a/app/templates/admin_stream.html b/app/templates/admin_stream.html index 22e066d..68091c7 100644 --- a/app/templates/admin_stream.html +++ b/app/templates/admin_stream.html @@ -7,13 +7,6 @@ {{ utils.display_object(inbox_object.relates_to_anybox_object) }} {% elif inbox_object.ap_type in ["Article", "Note", "Video"] %} {{ utils.display_object(inbox_object) }} - {% if inbox_object.liked_via_outbox_object_ap_id %} - {{ utils.admin_undo_button(inbox_object.liked_via_outbox_object_ap_id, "Unlike") }} - {% else %} - {{ utils.admin_like_button(inbox_object.ap_id) }} - {% endif %} - {{ utils.admin_announce_button(inbox_object.ap_id) }} - {{ utils.admin_reply_button(inbox_object.ap_id) }} {% endif %} {% endfor %} diff --git a/app/templates/followers.html b/app/templates/followers.html index 264e279..4a0429f 100644 --- a/app/templates/followers.html +++ b/app/templates/followers.html @@ -1,4 +1,4 @@ -{%- import "utils.html" as utils -%} +{%- import "utils.html" as utils with context -%} {% extends "layout.html" %} {% block content %} {% include "header.html" %} diff --git a/app/templates/header.html b/app/templates/header.html index 4a86662..1fc0f3e 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -14,8 +14,8 @@ {%- macro header_link(url, text) -%} -{% set url_for = request.url_for(url) %} -{{ text }} +{% set url_for = request.app.router.url_path_for(url) %} +{{ text }} {% endmacro %}
diff --git a/app/templates/index.html b/app/templates/index.html index c325678..5b672dd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -4,8 +4,6 @@ {% include "header.html" %} {% for outbox_object in objects %} -{{ outbox_object.likes_count }} -{{ outbox_object.announces_count }} {{ utils.display_object(outbox_object) }} {% endfor %} diff --git a/app/templates/object.html b/app/templates/object.html index 65daa80..0ebcbad 100644 --- a/app/templates/object.html +++ b/app/templates/object.html @@ -5,7 +5,12 @@ {% macro display_replies_tree(replies_tree_node) %} -{{ utils.display_object(replies_tree_node.ap_object) }} +{% if replies_tree_node.is_requested %} + {{ utils.display_object_expanded(replies_tree_node.ap_object) }} +{% else %} + {{ utils.display_object(replies_tree_node.ap_object) }} +{% endif %} + {% for child in replies_tree_node.children %} {{ display_replies_tree(child) }} {% endfor %} diff --git a/app/templates/utils.html b/app/templates/utils.html index 20029c8..1b73aea 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -60,7 +60,6 @@ {% endmacro %} {% macro display_actor(actor, actors_metadata) %} -{{ actors_metadata }} {% set metadata = actors_metadata.get(actor.ap_id) %}
@@ -71,19 +70,20 @@
{{ actor.handle }}
-{% if metadata %} +{% if is_admin and metadata %}
+{% elif object.ap_type == "Follow" %} + + {% if object.is_from_inbox %} +
+ {{ object.actor.display_name }} followed you + {{ object.ap_published_at | timeago }} +
+ {{ display_actor(object.actor, {}) }} + {% endif %} + {% endif %} {% endmacro %}