summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2022-07-08 14:00:29 +0100
committerGitHub <noreply@github.com>2022-07-08 14:00:29 +0100
commit757bc0caefa596e747278b3bcf4269ec50ffc759 (patch)
treecc4a772fd494051959a8aff81a27af282da02439
parentFix exception when using MSC3030 to look for remote federated events before r... (diff)
downloadsynapse-757bc0caefa596e747278b3bcf4269ec50ffc759.tar.xz
Fix notification count after a highlighted message (#13223)
Fixes #13196

Broke by #13005
Diffstat (limited to '')
-rw-r--r--changelog.d/13223.bugfix1
-rw-r--r--synapse/storage/databases/main/event_push_actions.py11
-rw-r--r--tests/storage/test_event_push_actions.py7
3 files changed, 16 insertions, 3 deletions
diff --git a/changelog.d/13223.bugfix b/changelog.d/13223.bugfix
new file mode 100644
index 0000000000..6ee3aed910
--- /dev/null
+++ b/changelog.d/13223.bugfix
@@ -0,0 +1 @@
+Fix bug where notification counts would get stuck after a highlighted message. Broke in v1.62.0.
diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py
index a3edcbb398..1a951ac02a 100644
--- a/synapse/storage/databases/main/event_push_actions.py
+++ b/synapse/storage/databases/main/event_push_actions.py
@@ -1016,9 +1016,14 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
                 upd.stream_ordering
             FROM (
                 SELECT user_id, room_id, count(*) as cnt,
-                    max(stream_ordering) as stream_ordering
-                FROM event_push_actions
-                WHERE ? < stream_ordering AND stream_ordering <= ?
+                    max(ea.stream_ordering) as stream_ordering
+                FROM event_push_actions AS ea
+                LEFT JOIN event_push_summary AS old USING (user_id, room_id)
+                WHERE ? < ea.stream_ordering AND ea.stream_ordering <= ?
+                    AND (
+                        old.last_receipt_stream_ordering IS NULL
+                        OR old.last_receipt_stream_ordering < ea.stream_ordering
+                    )
                     AND %s = 1
                 GROUP BY user_id, room_id
             ) AS upd
diff --git a/tests/storage/test_event_push_actions.py b/tests/storage/test_event_push_actions.py
index e68126777f..e8c53f16d9 100644
--- a/tests/storage/test_event_push_actions.py
+++ b/tests/storage/test_event_push_actions.py
@@ -196,6 +196,13 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
         _mark_read(10, 10)
         _assert_counts(0, 0)
 
+        _inject_actions(11, HIGHLIGHT)
+        _assert_counts(1, 1)
+        _mark_read(11, 11)
+        _assert_counts(0, 0)
+        _rotate(11)
+        _assert_counts(0, 0)
+
     def test_find_first_stream_ordering_after_ts(self) -> None:
         def add_event(so: int, ts: int) -> None:
             self.get_success(