diff options
author | Brendan Abolivier <babolivier@matrix.org> | 2020-06-10 16:21:16 +0100 |
---|---|---|
committer | Brendan Abolivier <babolivier@matrix.org> | 2020-06-10 16:21:16 +0100 |
commit | ef345c5a7b544aafa9c37bc2c4f626dfcef529f9 (patch) | |
tree | 75043212228a5c7b49c8e61498e99921928c79d4 /synapse/storage | |
parent | Rename dont_push into mark_unread (diff) | |
download | synapse-ef345c5a7b544aafa9c37bc2c4f626dfcef529f9.tar.xz |
Add a new unread_counter to sync responses
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/data_stores/main/event_push_actions.py | 25 |
1 files changed, 23 insertions, 2 deletions
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) |