From cdbc545d5e9472cc722849d33e639d95e0904eac Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 20 Nov 2022 10:13:17 +0100 Subject: [PATCH] Add a flag on new notifications --- app/admin.py | 16 ++++++++++------ app/scss/main.scss | 3 +++ app/templates/notifications.html | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/admin.py b/app/admin.py index df2e595..7725803 100644 --- a/app/admin.py +++ b/app/admin.py @@ -721,13 +721,9 @@ async def get_notifications( actors_metadata = await get_actors_metadata( db_session, [notif.actor for notif in notifications if notif.actor] ) - - for notif in notifications: - notif.is_new = False - await db_session.commit() - more_unread_count = 0 next_cursor = None + if notifications and remaining_count > page_size: decoded_next_cursor = notifications[-1].created_at next_cursor = pagination.encode_cursor(decoded_next_cursor) @@ -741,7 +737,8 @@ async def get_notifications( ) ) - return await templates.render_template( + # Render the template before we change the new flag on notifications + tpl_resp = await templates.render_template( db_session, request, "notifications.html", @@ -753,6 +750,13 @@ async def get_notifications( }, ) + if len({notif.id for notif in notifications if notif.is_new}): + for notif in notifications: + notif.is_new = False + await db_session.commit() + + return tpl_resp + @router.get("/object") async def admin_object( diff --git a/app/scss/main.scss b/app/scss/main.scss index dc99b1c..b8188a4 100644 --- a/app/scss/main.scss +++ b/app/scss/main.scss @@ -467,6 +467,9 @@ a.label-btn { span { color: $muted-color; } + span.new { + color: $secondary-color; + } } .actor-metadata { color: $muted-color; diff --git a/app/templates/notifications.html b/app/templates/notifications.html index d91b392..b59eaeb 100644 --- a/app/templates/notifications.html +++ b/app/templates/notifications.html @@ -10,6 +10,9 @@ {% if with_icon %}{{ utils.display_tiny_actor_icon(notif.actor) }}{% endif %} {{ notif.actor.display_name | clean_html(notif.actor) | safe }} {{ text }} {{ notif.created_at | timeago }} + {% if notif.is_new %} + new + {% endif %} {% endmacro %}