From a583733bd138568663f49649e847c2a480df0d10 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 6 Feb 2023 17:08:27 +0000 Subject: [PATCH 01/12] Validate vars early --- src/client.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index 2a579777117..db427e59383 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9422,12 +9422,14 @@ export class MatrixClient extends TypedEventEmitter Date: Mon, 6 Feb 2023 17:09:07 +0000 Subject: [PATCH 02/12] Split out unread counts for total and highlight to different logic blocks --- src/client.ts | 86 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/src/client.ts b/src/client.ts index db427e59383..a19007ff3ac 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9430,58 +9430,72 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri const oldActions = event.getPushActions(); const actions = cli.getPushActionsForEvent(event, true); + const isThreadEvent = !!event.threadRootId && !event.isThreadRoot; - const currentCount = room.getUnreadCountForEventContext(NotificationCountType.Highlight, event); + const currentHighlightCount = room.getUnreadCountForEventContext(NotificationCountType.Highlight, event); + + // Total count is used to typically increment a room notification counter, but not loudly highlight it. + const currentTotalCount = + (isThreadEvent + ? room.getThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total) + : room.getRoomUnreadNotificationCount(NotificationCountType.Total)) ?? 0; // Ensure the unread counts are kept up to date if the event is encrypted // We also want to make sure that the notification count goes up if we already // have encrypted events to avoid other code from resetting 'highlight' to zero. const oldHighlight = !!oldActions?.tweaks?.highlight; const newHighlight = !!actions?.tweaks?.highlight; - if (oldHighlight !== newHighlight || currentCount > 0) { + + let hasReadEvent; + if (isThreadEvent) { + const thread = room.getThread(event.threadRootId); + hasReadEvent = thread + ? thread.hasUserReadEvent(ourUserId, eventId) + : // If the thread object does not exist in the room yet, we don't + // want to calculate notification for this event yet. We have not + // restored the read receipts yet and can't accurately calculate + // notifications at this stage. + // + // This issue can likely go away when MSC3874 is implemented + true; + } else { + hasReadEvent = room.hasUserReadEvent(ourUserId, eventId); + } + + if (hasReadEvent) { + // If the event has been read, ignore it. + return; + } + + if (oldHighlight !== newHighlight || currentHighlightCount > 0) { // TODO: Handle mentions received while the client is offline // See also https://github.com/vector-im/element-web/issues/9069 - let hasReadEvent; + let newCount = currentHighlightCount; + if (newHighlight && !oldHighlight) newCount++; + if (!newHighlight && oldHighlight) newCount--; + if (isThreadEvent) { - const thread = room.getThread(event.threadRootId); - hasReadEvent = thread - ? thread.hasUserReadEvent(cli.getUserId()!, event.getId()!) - : // If the thread object does not exist in the room yet, we don't - // want to calculate notification for this event yet. We have not - // restored the read receipts yet and can't accurately calculate - // highlight notifications at this stage. - // - // This issue can likely go away when MSC3874 is implemented - true; + room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Highlight, newCount); } else { - hasReadEvent = room.hasUserReadEvent(cli.getUserId()!, event.getId()!); + room.setUnreadNotificationCount(NotificationCountType.Highlight, newCount); } + } - if (!hasReadEvent) { - let newCount = currentCount; - if (newHighlight && !oldHighlight) newCount++; - if (!newHighlight && oldHighlight) newCount--; - - if (isThreadEvent) { - room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Highlight, newCount); - } else { - room.setUnreadNotificationCount(NotificationCountType.Highlight, newCount); - } + // `notify` is used in practice for incrementing the total count + const oldNotfy = !!oldActions?.notify; + const newNotify = !!actions?.notify; - // Fix 'Mentions Only' rooms from not having the right badge count - const totalCount = - (isThreadEvent - ? room.getThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total) - : room.getRoomUnreadNotificationCount(NotificationCountType.Total)) ?? 0; + if (oldNotfy !== newNotify || currentTotalCount > 0) { + // We've recalculated that the event should or should not notify, and the total is > 0 + let newCount = currentTotalCount; + if (newNotify && !oldNotfy) newCount++; + if (!newNotify && oldNotfy) newCount--; - if (totalCount < newCount) { - if (isThreadEvent) { - room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total, newCount); - } else { - room.setUnreadNotificationCount(NotificationCountType.Total, newCount); - } - } + if (isThreadEvent) { + room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total, newCount); + } else { + room.setUnreadNotificationCount(NotificationCountType.Total, newCount); } } } From 4cc7f5b13e03113e5f3cd266f588f429fa44cf61 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 6 Feb 2023 17:09:30 +0000 Subject: [PATCH 03/12] Add tests for ignoring non notifying events --- spec/unit/notifications.spec.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/unit/notifications.spec.ts b/spec/unit/notifications.spec.ts index 594740e285a..92b236b84b8 100644 --- a/spec/unit/notifications.spec.ts +++ b/spec/unit/notifications.spec.ts @@ -192,6 +192,34 @@ describe("fixNotificationCountOnDecryption", () => { expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight)).toBe(0); }); + it("does not change the total room count when an event is marked as non-notifying", () => { + // Server sets the value to 1 + // This was in the main timeline + room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 0); + room.setUnreadNotificationCount(NotificationCountType.Highlight, 0); + + event.getPushActions = jest.fn().mockReturnValue(mkPushAction(true, false)); + mockClient.getPushActionsForEvent = jest.fn().mockReturnValue(mkPushAction(false, false)); + + fixNotificationCountOnDecryption(mockClient, event); + expect(room.getUnreadNotificationCount(NotificationCountType.Total)).toBe(0); + expect(room.getUnreadNotificationCount(NotificationCountType.Highlight)).toBe(0); + }); + + it("does not change the total room count when a threaded event is marked as non-notifying", () => { + // Server sets the value to 1 + // This was in the main thread + room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 0); + room.setUnreadNotificationCount(NotificationCountType.Highlight, 0); + + threadEvent.getPushActions = jest.fn().mockReturnValue(mkPushAction(true, false)); + mockClient.getPushActionsForEvent = jest.fn().mockReturnValue(mkPushAction(false, false)); + + fixNotificationCountOnDecryption(mockClient, event); + expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total)).toBe(0); + expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight)).toBe(0); + }); + it("emits events", () => { const cb = jest.fn(); room.on(RoomEvent.UnreadNotifications, cb); From 8bc52665423599a3c351e55b7b1e9fd9a5be76d5 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 6 Feb 2023 17:09:40 +0000 Subject: [PATCH 04/12] Fix possibly incorrect tests? --- spec/unit/notifications.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/notifications.spec.ts b/spec/unit/notifications.spec.ts index 92b236b84b8..d66f9b92797 100644 --- a/spec/unit/notifications.spec.ts +++ b/spec/unit/notifications.spec.ts @@ -134,7 +134,7 @@ describe("fixNotificationCountOnDecryption", () => { fixNotificationCountOnDecryption(mockClient, event); - expect(room.getUnreadNotificationCount(NotificationCountType.Total)).toBe(2); + expect(room.getUnreadNotificationCount(NotificationCountType.Total)).toBe(3); expect(room.getUnreadNotificationCount(NotificationCountType.Highlight)).toBe(1); }); @@ -154,7 +154,7 @@ describe("fixNotificationCountOnDecryption", () => { fixNotificationCountOnDecryption(mockClient, threadEvent); - expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total)).toBe(1); + expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total)).toBe(2); expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight)).toBe(1); }); From a27976125951a4156439e11ec087d7af1bf1d5eb Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 6 Feb 2023 17:17:59 +0000 Subject: [PATCH 05/12] lint fix --- src/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client.ts b/src/client.ts index a19007ff3ac..662c384eadd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9434,12 +9434,12 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri const isThreadEvent = !!event.threadRootId && !event.isThreadRoot; const currentHighlightCount = room.getUnreadCountForEventContext(NotificationCountType.Highlight, event); - + // Total count is used to typically increment a room notification counter, but not loudly highlight it. const currentTotalCount = - (isThreadEvent - ? room.getThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total) - : room.getRoomUnreadNotificationCount(NotificationCountType.Total)) ?? 0; + (isThreadEvent + ? room.getThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total) + : room.getRoomUnreadNotificationCount(NotificationCountType.Total)) ?? 0; // Ensure the unread counts are kept up to date if the event is encrypted // We also want to make sure that the notification count goes up if we already From 32ff06486f7284d5ff0f5d05f371ae0fc3abcca2 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 09:23:09 +0000 Subject: [PATCH 06/12] Refactor currentTotalCount --- src/client.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client.ts b/src/client.ts index 662c384eadd..feefb1f0d69 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9436,10 +9436,7 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri const currentHighlightCount = room.getUnreadCountForEventContext(NotificationCountType.Highlight, event); // Total count is used to typically increment a room notification counter, but not loudly highlight it. - const currentTotalCount = - (isThreadEvent - ? room.getThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total) - : room.getRoomUnreadNotificationCount(NotificationCountType.Total)) ?? 0; + const currentTotalCount = room.getUnreadCountForEventContext(NotificationCountType.Total, event); // Ensure the unread counts are kept up to date if the event is encrypted // We also want to make sure that the notification count goes up if we already @@ -9483,7 +9480,8 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri } // `notify` is used in practice for incrementing the total count - const oldNotfy = !!oldActions?.notify; + // If `oldActions` is not defined, we assume `notify` is true. + const oldNotfy = oldActions === null || oldActions?.notify === true; const newNotify = !!actions?.notify; if (oldNotfy !== newNotify || currentTotalCount > 0) { From 509654d098de30578abdb5b76d684d6d241451e8 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 09:23:17 +0000 Subject: [PATCH 07/12] Track Total locally too --- src/sync.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/sync.ts b/src/sync.ts index 11fe3cc102b..a5e58330fe2 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1300,15 +1300,20 @@ export class SyncApi { const encrypted = client.isRoomEncrypted(room.roomId); // we do this first so it's correct when any of the events fire if (joinObj.unread_notifications) { - room.setUnreadNotificationCount( - NotificationCountType.Total, - joinObj.unread_notifications.notification_count ?? 0, - ); - - // We track unread notifications ourselves in encrypted rooms, so don't - // bother setting it here. We trust our calculations better than the - // server's for this case, and therefore will assume that our non-zero - // count is accurate. + /** + * We track unread notifications ourselves in encrypted rooms, so don't + * bother setting it here. We trust our calculations better than the + * server's for this case, and therefore will assume that our non-zero + * count is accurate. + * @see import("./client").fixNotificationCountOnDecryption + */ + if (!encrypted || room.getUnreadNotificationCount(NotificationCountType.Total) <= 0) { + room.setUnreadNotificationCount( + NotificationCountType.Total, + joinObj.unread_notifications.notification_count ?? 0, + ); + } + if (!encrypted || room.getUnreadNotificationCount(NotificationCountType.Highlight) <= 0) { room.setUnreadNotificationCount( NotificationCountType.Highlight, From 87239aeb1cdb6afea1a0fc104a34d5b2a0958bd7 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 09:49:06 +0000 Subject: [PATCH 08/12] Lots of total count assumptions and comments --- src/client.ts | 13 ++++--------- src/sync.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/client.ts b/src/client.ts index feefb1f0d69..08a093534d0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9480,20 +9480,15 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri } // `notify` is used in practice for incrementing the total count - // If `oldActions` is not defined, we assume `notify` is true. - const oldNotfy = oldActions === null || oldActions?.notify === true; const newNotify = !!actions?.notify; - if (oldNotfy !== newNotify || currentTotalCount > 0) { + // The room total count is NEVER incremented by the server for encrypted rooms. + if (newNotify) { // We've recalculated that the event should or should not notify, and the total is > 0 - let newCount = currentTotalCount; - if (newNotify && !oldNotfy) newCount++; - if (!newNotify && oldNotfy) newCount--; - if (isThreadEvent) { - room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total, newCount); + room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total, currentTotalCount+1); } else { - room.setUnreadNotificationCount(NotificationCountType.Total, newCount); + room.setUnreadNotificationCount(NotificationCountType.Total, currentTotalCount+1); } } } diff --git a/src/sync.ts b/src/sync.ts index a5e58330fe2..302696f7e5e 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1298,16 +1298,21 @@ export class SyncApi { const accountDataEvents = this.mapSyncEventsFormat(joinObj.account_data); const encrypted = client.isRoomEncrypted(room.roomId); - // we do this first so it's correct when any of the events fire if (joinObj.unread_notifications) { /** * We track unread notifications ourselves in encrypted rooms, so don't * bother setting it here. We trust our calculations better than the * server's for this case, and therefore will assume that our non-zero * count is accurate. + * * @see import("./client").fixNotificationCountOnDecryption */ - if (!encrypted || room.getUnreadNotificationCount(NotificationCountType.Total) <= 0) { + // We store the server-provided value first so it's correct when any of the events fire + if (!encrypted || joinObj.unread_notifications.notification_count === 0) { + // In an encrypted room, if the room has notifications enabled then it's typical for + // the server to flag all new messages as unread. However, some push rules calculate + // events as ignored based on their event contents (e.g. ignoring msgtype=m.notice messages) + // so we want to calculate this figure on the client in all cases. room.setUnreadNotificationCount( NotificationCountType.Total, joinObj.unread_notifications.notification_count ?? 0, @@ -1315,6 +1320,7 @@ export class SyncApi { } if (!encrypted || room.getUnreadNotificationCount(NotificationCountType.Highlight) <= 0) { + // If the locally stored highlight count is zero, use the server provided value. room.setUnreadNotificationCount( NotificationCountType.Highlight, joinObj.unread_notifications.highlight_count ?? 0, From 22715930a8ba959a3206695d85471db00291115e Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 09:56:54 +0000 Subject: [PATCH 09/12] Adjust for threading too --- src/client.ts | 4 ++-- src/sync.ts | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index 08a093534d0..d2690caf443 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9482,9 +9482,9 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri // `notify` is used in practice for incrementing the total count const newNotify = !!actions?.notify; - // The room total count is NEVER incremented by the server for encrypted rooms. + // The room total count is NEVER incremented by the server for encrypted rooms. We basically ignore + // the server here as it's always going to tell us to increment for encrypted events. if (newNotify) { - // We've recalculated that the event should or should not notify, and the total is > 0 if (isThreadEvent) { room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total, currentTotalCount+1); } else { diff --git a/src/sync.ts b/src/sync.ts index 302696f7e5e..b933317c8bc 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1298,6 +1298,7 @@ export class SyncApi { const accountDataEvents = this.mapSyncEventsFormat(joinObj.account_data); const encrypted = client.isRoomEncrypted(room.roomId); + // We store the server-provided value first so it's correct when any of the events fire. if (joinObj.unread_notifications) { /** * We track unread notifications ourselves in encrypted rooms, so don't @@ -1307,7 +1308,6 @@ export class SyncApi { * * @see import("./client").fixNotificationCountOnDecryption */ - // We store the server-provided value first so it's correct when any of the events fire if (!encrypted || joinObj.unread_notifications.notification_count === 0) { // In an encrypted room, if the room has notifications enabled then it's typical for // the server to flag all new messages as unread. However, some push rules calculate @@ -1337,11 +1337,14 @@ export class SyncApi { // decryption room.resetThreadUnreadNotificationCount(Object.keys(unreadThreadNotifications)); for (const [threadId, unreadNotification] of Object.entries(unreadThreadNotifications)) { - room.setThreadUnreadNotificationCount( - threadId, - NotificationCountType.Total, - unreadNotification.notification_count ?? 0, - ); + if (!encrypted || unreadNotification.notification_count === 0) { + + room.setThreadUnreadNotificationCount( + threadId, + NotificationCountType.Total, + unreadNotification.notification_count ?? 0, + ); + } const hasNoNotifications = room.getThreadUnreadNotificationCount(threadId, NotificationCountType.Highlight) <= 0; From 698f66f1fa6bcda521b9bbe3376c437a87f6437a Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 10:08:29 +0000 Subject: [PATCH 10/12] Fixup tests --- spec/unit/notifications.spec.ts | 7 ++----- src/client.ts | 6 +++--- src/sync.ts | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/spec/unit/notifications.spec.ts b/spec/unit/notifications.spec.ts index d66f9b92797..6dd2b50489a 100644 --- a/spec/unit/notifications.spec.ts +++ b/spec/unit/notifications.spec.ts @@ -193,9 +193,8 @@ describe("fixNotificationCountOnDecryption", () => { }); it("does not change the total room count when an event is marked as non-notifying", () => { - // Server sets the value to 1 - // This was in the main timeline room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 0); + room.setUnreadNotificationCount(NotificationCountType.Total, 0); room.setUnreadNotificationCount(NotificationCountType.Highlight, 0); event.getPushActions = jest.fn().mockReturnValue(mkPushAction(true, false)); @@ -207,10 +206,8 @@ describe("fixNotificationCountOnDecryption", () => { }); it("does not change the total room count when a threaded event is marked as non-notifying", () => { - // Server sets the value to 1 - // This was in the main thread room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 0); - room.setUnreadNotificationCount(NotificationCountType.Highlight, 0); + room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight, 0); threadEvent.getPushActions = jest.fn().mockReturnValue(mkPushAction(true, false)); mockClient.getPushActionsForEvent = jest.fn().mockReturnValue(mkPushAction(false, false)); diff --git a/src/client.ts b/src/client.ts index d2690caf443..7562b277663 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9435,9 +9435,6 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri const currentHighlightCount = room.getUnreadCountForEventContext(NotificationCountType.Highlight, event); - // Total count is used to typically increment a room notification counter, but not loudly highlight it. - const currentTotalCount = room.getUnreadCountForEventContext(NotificationCountType.Total, event); - // Ensure the unread counts are kept up to date if the event is encrypted // We also want to make sure that the notification count goes up if we already // have encrypted events to avoid other code from resetting 'highlight' to zero. @@ -9479,6 +9476,9 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri } } + // Total count is used to typically increment a room notification counter, but not loudly highlight it. + const currentTotalCount = room.getUnreadCountForEventContext(NotificationCountType.Total, event); + // `notify` is used in practice for incrementing the total count const newNotify = !!actions?.notify; diff --git a/src/sync.ts b/src/sync.ts index b933317c8bc..e656cc6377e 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1338,7 +1338,6 @@ export class SyncApi { room.resetThreadUnreadNotificationCount(Object.keys(unreadThreadNotifications)); for (const [threadId, unreadNotification] of Object.entries(unreadThreadNotifications)) { if (!encrypted || unreadNotification.notification_count === 0) { - room.setThreadUnreadNotificationCount( threadId, NotificationCountType.Total, From fea6a3e746f7da0b45c5101786bd4c753075d3fe Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 10:09:31 +0000 Subject: [PATCH 11/12] a word --- src/sync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sync.ts b/src/sync.ts index e656cc6377e..17864f928d4 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1310,7 +1310,7 @@ export class SyncApi { */ if (!encrypted || joinObj.unread_notifications.notification_count === 0) { // In an encrypted room, if the room has notifications enabled then it's typical for - // the server to flag all new messages as unread. However, some push rules calculate + // the server to flag all new messages as notifying. However, some push rules calculate // events as ignored based on their event contents (e.g. ignoring msgtype=m.notice messages) // so we want to calculate this figure on the client in all cases. room.setUnreadNotificationCount( From 71761e7b8ba50ee45a0e2009b1b9a634ae2aaf8d Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 7 Feb 2023 10:15:45 +0000 Subject: [PATCH 12/12] lint fix --- src/client.ts | 8 ++++++-- src/sync.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index 137c542fefb..c16ea6bdd4d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9547,9 +9547,13 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri // the server here as it's always going to tell us to increment for encrypted events. if (newNotify) { if (isThreadEvent) { - room.setThreadUnreadNotificationCount(event.threadRootId, NotificationCountType.Total, currentTotalCount+1); + room.setThreadUnreadNotificationCount( + event.threadRootId, + NotificationCountType.Total, + currentTotalCount + 1, + ); } else { - room.setUnreadNotificationCount(NotificationCountType.Total, currentTotalCount+1); + room.setUnreadNotificationCount(NotificationCountType.Total, currentTotalCount + 1); } } } diff --git a/src/sync.ts b/src/sync.ts index 6984cf27e55..bfd6029f0b3 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1306,7 +1306,7 @@ export class SyncApi { * bother setting it here. We trust our calculations better than the * server's for this case, and therefore will assume that our non-zero * count is accurate. - * + * * @see import("./client").fixNotificationCountOnDecryption */ if (!encrypted || joinObj.unread_notifications.notification_count === 0) {