From 4834e12a3a88c41977c6e62f1a0b5f98728f3dfc Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 4 Mar 2019 21:41:20 -0700 Subject: [PATCH] Calculate unread badges for encrypted events --- src/client.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 434a24d34..fe3433fc4 100644 --- a/src/client.js +++ b/src/client.js @@ -2304,7 +2304,20 @@ function _membershipChange(client, roomId, userId, membership, reason, callback) */ MatrixClient.prototype.getPushActionsForEvent = function(event, ignoreCache = false) { if (!event.getPushActions() || ignoreCache) { - event.setPushActions(this._pushProcessor.actionsForEvent(event)); + const oldActions = event.getPushActions(); + const actions = this._pushProcessor.actionsForEvent(event); + event.setPushActions(actions); + + // Ensure the unread counts are kept up to date if the event is encrypted + const oldHighlight = oldActions && oldActions.tweaks ? !!oldActions.tweaks.highlight : false; + const newHighlight = actions && actions.tweaks ? !!actions.tweaks.highlight : false; + if (oldHighlight !== newHighlight && event.isEncrypted()) { + const room = this.getRoom(event.getRoomId()); + if (room) { + const current = room.getUnreadNotificationCount("highlight"); + room.setUnreadNotificationCount("highlight", newHighlight ? current + 1 : current - 1); + } + } } return event.getPushActions(); };