Add a flag on new notifications

main
Thomas Sileo 2022-11-20 10:13:17 +01:00
parent fbc46e0517
commit cdbc545d5e
3 changed files with 16 additions and 6 deletions

View File

@ -721,13 +721,9 @@ async def get_notifications(
actors_metadata = await get_actors_metadata( actors_metadata = await get_actors_metadata(
db_session, [notif.actor for notif in notifications if notif.actor] 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 more_unread_count = 0
next_cursor = None next_cursor = None
if notifications and remaining_count > page_size: if notifications and remaining_count > page_size:
decoded_next_cursor = notifications[-1].created_at decoded_next_cursor = notifications[-1].created_at
next_cursor = pagination.encode_cursor(decoded_next_cursor) 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, db_session,
request, request,
"notifications.html", "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") @router.get("/object")
async def admin_object( async def admin_object(

View File

@ -467,6 +467,9 @@ a.label-btn {
span { span {
color: $muted-color; color: $muted-color;
} }
span.new {
color: $secondary-color;
}
} }
.actor-metadata { .actor-metadata {
color: $muted-color; color: $muted-color;

View File

@ -10,6 +10,9 @@
<a href="{{ url_for("admin_profile") }}?actor_id={{ notif.actor.ap_id }}"> <a href="{{ url_for("admin_profile") }}?actor_id={{ notif.actor.ap_id }}">
{% if with_icon %}{{ utils.display_tiny_actor_icon(notif.actor) }}{% endif %} {{ notif.actor.display_name | clean_html(notif.actor) | safe }}</a> {{ text }} {% if with_icon %}{{ utils.display_tiny_actor_icon(notif.actor) }}{% endif %} {{ notif.actor.display_name | clean_html(notif.actor) | safe }}</a> {{ text }}
<span title="{{ notif.created_at.isoformat() }}">{{ notif.created_at | timeago }}</span> <span title="{{ notif.created_at.isoformat() }}">{{ notif.created_at | timeago }}</span>
{% if notif.is_new %}
<span class="new">new</span>
{% endif %}
</div> </div>
{% endmacro %} {% endmacro %}