From 8085fa335126bcfd5e88b1ce142098c52adb6bd3 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 26 Feb 2023 11:22:42 +0200 Subject: [PATCH] make modmail appear in /search/messages --- files/routes/notifications.py | 5 ++++- files/routes/search.py | 6 +++++- files/routes/users.py | 2 +- migrations/20230226-search-modmail.sql | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 migrations/20230226-search-modmail.sql diff --git a/files/routes/notifications.py b/files/routes/notifications.py index fb1efb996..adc320f37 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -53,7 +53,10 @@ def notifications_modmail(v): try: page = max(int(request.values.get("page", 1)), 1) except: page = 1 - comments = g.db.query(Comment).filter(Comment.sentto==2).order_by(Comment.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all() + comments = g.db.query(Comment).filter_by( + sentto=MODMAIL_ID, + level=1, + ).order_by(Comment.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all() next_exists = (len(comments) > PAGE_SIZE) listing = comments[:PAGE_SIZE] diff --git a/files/routes/search.py b/files/routes/search.py index 43f09093a..0b3896c75 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -297,11 +297,15 @@ def searchmessages(v:User): criteria = searchparse(query) + dm_conditions = [Comment.author_id == v.id, Comment.sentto == v.id] + if v.admin_level >= PERMS['VIEW_MODMAIL']: + dm_conditions.append(Comment.sentto == MODMAIL_ID), + comments = g.db.query(Comment.id) \ .filter( Comment.sentto != None, - or_(Comment.author_id == v.id, Comment.sentto == v.id), Comment.parent_submission == None, + or_(*dm_conditions), ) if 'author' in criteria: diff --git a/files/routes/users.py b/files/routes/users.py index 3425a636e..7efe327b1 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -605,7 +605,7 @@ def messagereply(v:User): parent_comment_id=id, top_comment_id=parent.top_comment_id, level=parent.level + 1, - sentto=user_id, + sentto=parent.sentto, body=body, body_html=body_html, ) diff --git a/migrations/20230226-search-modmail.sql b/migrations/20230226-search-modmail.sql new file mode 100644 index 000000000..25408fb65 --- /dev/null +++ b/migrations/20230226-search-modmail.sql @@ -0,0 +1 @@ +select id from comments where parent_submission is null and sentto is null and (top_comment_id in (select id from comments where sentto = 2) or parent_comment_id in (select id from comments where sentto = 2));