Add a new unread_counter to sync responses

pull/7673/head
Brendan Abolivier 2020-06-10 16:21:16 +01:00
parent 6f6a4bfc07
commit ef345c5a7b
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD
3 changed files with 28 additions and 3 deletions

View File

@ -1895,6 +1895,7 @@ class SyncHandler(object):
if notifs is not None: if notifs is not None:
unread_notifications["notification_count"] = notifs["notify_count"] unread_notifications["notification_count"] = notifs["notify_count"]
unread_notifications["highlight_count"] = notifs["highlight_count"] unread_notifications["highlight_count"] = notifs["highlight_count"]
unread_notifications["unread_count"] = notifs["unread_count"]
sync_result_builder.joined.append(room_sync) sync_result_builder.joined.append(room_sync)

View File

@ -39,7 +39,10 @@ def get_badge_count(store, user_id):
) )
# return one badge count per conversation, as count per # return one badge count per conversation, as count per
# message is so noisy as to be almost useless # 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 return badge

View File

@ -133,6 +133,7 @@ class EventPushActionsWorkerStore(SQLBaseStore):
" user_id = ?" " user_id = ?"
" AND room_id = ?" " AND room_id = ?"
" AND stream_ordering > ?" " AND stream_ordering > ?"
" AND notif = 1"
) )
txn.execute(sql, (user_id, room_id, stream_ordering)) txn.execute(sql, (user_id, room_id, stream_ordering))
@ -150,6 +151,22 @@ class EventPushActionsWorkerStore(SQLBaseStore):
if rows: if rows:
notify_count += rows[0][0] 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 # Now get the number of highlights
sql = ( sql = (
"SELECT count(*)" "SELECT count(*)"
@ -165,7 +182,11 @@ class EventPushActionsWorkerStore(SQLBaseStore):
row = txn.fetchone() row = txn.fetchone()
highlight_count = row[0] if row else 0 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 @defer.inlineCallbacks
def get_push_action_users_in_range(self, min_stream_ordering, max_stream_ordering): 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 max(stream_ordering) as stream_ordering
FROM event_push_actions FROM event_push_actions
WHERE ? <= stream_ordering AND stream_ordering < ? WHERE ? <= stream_ordering AND stream_ordering < ?
AND highlight = 0 AND highlight = 0 AND notif = 1
GROUP BY user_id, room_id GROUP BY user_id, room_id
) AS upd ) AS upd
LEFT JOIN event_push_summary AS old USING (user_id, room_id) LEFT JOIN event_push_summary AS old USING (user_id, room_id)