From fffbd22122c208c434335cc59507488ac4b5a24d Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 23 Feb 2024 12:20:26 +0000 Subject: [PATCH] Ignore notification counts from rooms you've left This fixes a bug in https://github.com/element-hq/synapse/issues/16904, where notifications the user had received from rooms they had left were still being counted. This was most apparent for rejected invites, where you "leave" the room you were invited to without sending a read receipt in that room, thus clearing the notification. --- .../databases/main/event_push_actions.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py index d7aa8a0ee0..9a68cda0bd 100644 --- a/synapse/storage/databases/main/event_push_actions.py +++ b/synapse/storage/databases/main/event_push_actions.py @@ -404,7 +404,11 @@ def _get_unread_counts_by_room_for_user_txn( SELECT e.room_id, notif_count, e.stream_ordering, e.thread_id, last_receipt_stream_ordering, ev.stream_ordering AS receipt_stream_ordering FROM event_push_summary AS e - INNER JOIN local_current_membership USING (user_id, room_id) + INNER JOIN local_current_membership as lcm ON ( + e.user_id = lcm.user_id + AND e.room_id = lcm.room_id + AND lcm.membership = 'join' + ) LEFT JOIN receipts_linearized AS r ON ( e.user_id = r.user_id AND e.room_id = r.room_id @@ -472,7 +476,11 @@ def _get_unread_counts_by_room_for_user_txn( SELECT e.room_id, e.stream_ordering, e.thread_id, ev.stream_ordering AS receipt_stream_ordering FROM event_push_actions AS e - INNER JOIN local_current_membership USING (user_id, room_id) + INNER JOIN local_current_membership as lcm ON ( + e.user_id = lcm.user_id + AND e.room_id = lcm.room_id + AND lcm.membership = 'join' + ) LEFT JOIN receipts_linearized AS r ON ( e.user_id = r.user_id AND e.room_id = r.room_id @@ -514,7 +522,11 @@ def _get_unread_counts_by_room_for_user_txn( SELECT e.room_id, e.stream_ordering, e.thread_id, ev.stream_ordering AS receipt_stream_ordering FROM event_push_actions AS e - INNER JOIN local_current_membership USING (user_id, room_id) + INNER JOIN local_current_membership as lcm ON ( + e.user_id = lcm.user_id + AND e.room_id = lcm.room_id + AND lcm.membership = 'join' + ) LEFT JOIN receipts_linearized AS r ON ( e.user_id = r.user_id AND e.room_id = r.room_id