From 9eab252e5b8ca7b953e9a797ebe725fd0e034877 Mon Sep 17 00:00:00 2001 From: TLSM Date: Mon, 21 Nov 2022 23:08:31 -0500 Subject: [PATCH] Fix reply/mention notifications from muted users. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consider the case of the current /notifications filter condition: WHERE ... NOT ((comments.sentto = 2) AND (users.is_muted)) SELECT 1 WHERE NOT ((null = 2) AND (true)); ⇒ 0 rows SELECT 1 WHERE NOT ((1 = 2) AND (true)); ⇒ 1 row SELECT 1 WHERE NOT ((2 = 2) AND (true)); ⇒ 0 rows We want the first expression, where comments.sentto = null, to evaluate to false, not to null, so it negates to true. Behavior as written is: SELECT 1 WHERE NOT ((null = 2) AND (true)); → SELECT 1 WHERE NOT (null AND true); → SELECT 1 WHERE NOT null; → SELECT 1 WHERE null; Which guarantees a null return set. If we check first for non-nullity: SELECT 1 WHERE NOT ((null IS NOT null) AND (null = 2) AND (true)); ⇒ 1 SELECT 1 WHERE NOT ((1 IS NOT null) AND (1 = 2) AND (true)); ⇒ 1 SELECT 1 WHERE NOT ((2 IS NOT null) AND (2 = 2) AND (true)); ⇒ 0 --- files/classes/user.py | 2 +- files/routes/notifications.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 00b20cf9e..71d4fc5fb 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -591,7 +591,7 @@ class User(Base): Notification.user_id == self.id, Comment.is_banned == False, Comment.deleted_utc == 0, - not_(and_(Comment.sentto == MODMAIL_ID, User.is_muted)), + not_(and_(Comment.sentto != None, Comment.sentto == MODMAIL_ID, User.is_muted)), )) if not self.can_see_shadowbanned: diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 696a72c34..0654abc7d 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -273,7 +273,7 @@ def notifications(v): Comment.deleted_utc == 0, Comment.body_html.notlike('%

New site mention%