From a2774d52858ab5ed3ba90db391a96a1866caf446 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 1 Feb 2024 18:14:51 +0200 Subject: [PATCH] order modmail notifs by recency of last message --- files/routes/notifications.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/files/routes/notifications.py b/files/routes/notifications.py index e16e32be1..044a3f397 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -138,10 +138,9 @@ def notifications_messages(v): def notifications_modmail(v): page = get_page() - comments = g.db.query(Comment).filter_by( - sentto=MODMAIL_ID, - level=1, - ) + sq = g.db.query(Comment.top_comment_id, Comment.created_utc).distinct(Comment.top_comment_id).filter_by(sentto=MODMAIL_ID, level=2).order_by(Comment.top_comment_id, Comment.created_utc.desc()).subquery() + + comments = g.db.query(Comment).filter(Comment.id == sq.c.top_comment_id).order_by(sq.c.created_utc.desc()) total = comments.count() listing = comments.order_by(Comment.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()