summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/sync.py1
-rw-r--r--synapse/push/push_tools.py5
-rw-r--r--synapse/storage/data_stores/main/event_push_actions.py25
3 files changed, 28 insertions, 3 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 6bdb24baff..cec0ca427e 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -1895,6 +1895,7 @@ class SyncHandler(object):
                 if notifs is not None:
                     unread_notifications["notification_count"] = notifs["notify_count"]
                     unread_notifications["highlight_count"] = notifs["highlight_count"]
+                    unread_notifications["unread_count"] = notifs["unread_count"]
 
                 sync_result_builder.joined.append(room_sync)
 
diff --git a/synapse/push/push_tools.py b/synapse/push/push_tools.py
index 5dae4648c0..9f264ca4a4 100644
--- a/synapse/push/push_tools.py
+++ b/synapse/push/push_tools.py
@@ -39,7 +39,10 @@ def get_badge_count(store, user_id):
             )
             # return one badge count per conversation, as count per
             # message is so noisy as to be almost useless
-            badge += 1 if notifs["notify_count"] else 0
+            # We're populating this badge using the unread_count (instead of the
+            # notify_count) as this badge is the number of missed messages, not the
+            # number of missed notifications.
+            badge += 1 if notifs["unread_count"] else 0
     return badge
 
 
diff --git a/synapse/storage/data_stores/main/event_push_actions.py b/synapse/storage/data_stores/main/event_push_actions.py
index a86a6a1bed..9922fda506 100644
--- a/synapse/storage/data_stores/main/event_push_actions.py
+++ b/synapse/storage/data_stores/main/event_push_actions.py
@@ -133,6 +133,7 @@ class EventPushActionsWorkerStore(SQLBaseStore):
             " user_id = ?"
             " AND room_id = ?"
             " AND stream_ordering > ?"
+            " AND notif = 1"
         )
 
         txn.execute(sql, (user_id, room_id, stream_ordering))
@@ -150,6 +151,22 @@ class EventPushActionsWorkerStore(SQLBaseStore):
         if rows:
             notify_count += rows[0][0]
 
+        # Now get the number of unread messages in the room, i.e. messages that matched
+        # both a mark_unread rule and a notify one.
+        sql = (
+            "SELECT count(*)"
+            " FROM event_push_actions ea"
+            " WHERE"
+            " user_id = ?"
+            " AND room_id = ?"
+            " AND stream_ordering > ?"
+            " AND notif = 0"
+        )
+        txn.execute(sql, (user_id, room_id, stream_ordering))
+        row = txn.fetchone()
+        unread_count = row[0] if row else 0
+        unread_count += notify_count
+
         # Now get the number of highlights
         sql = (
             "SELECT count(*)"
@@ -165,7 +182,11 @@ class EventPushActionsWorkerStore(SQLBaseStore):
         row = txn.fetchone()
         highlight_count = row[0] if row else 0
 
-        return {"notify_count": notify_count, "highlight_count": highlight_count}
+        return {
+            "notify_count": notify_count,
+            "highlight_count": highlight_count,
+            "unread_count": unread_count,
+        }
 
     @defer.inlineCallbacks
     def get_push_action_users_in_range(self, min_stream_ordering, max_stream_ordering):
@@ -831,7 +852,7 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
                     max(stream_ordering) as stream_ordering
                 FROM event_push_actions
                 WHERE ? <= stream_ordering AND stream_ordering < ?
-                    AND highlight = 0
+                    AND highlight = 0 AND notif = 1
                 GROUP BY user_id, room_id
             ) AS upd
             LEFT JOIN event_push_summary AS old USING (user_id, room_id)