From 841cb09540af631cc03fa99714a5e23b91451483 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 15 Feb 2022 19:50:10 +0000 Subject: [PATCH 1/3] Fix delayed badge update for mentions in encrypted rooms Fixes https://github.com/vector-im/element-web/issues/20859 More detail on the issue --- src/stores/notifications/RoomNotificationState.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/stores/notifications/RoomNotificationState.ts b/src/stores/notifications/RoomNotificationState.ts index 782b86e4a57..9d5e65d6c9c 100644 --- a/src/stores/notifications/RoomNotificationState.ts +++ b/src/stores/notifications/RoomNotificationState.ts @@ -26,6 +26,7 @@ import * as RoomNotifs from '../../RoomNotifs'; import * as Unread from '../../Unread'; import { NotificationState } from "./NotificationState"; import { getUnsentMessages } from "../../components/structures/RoomStatusBar"; +import { logger } from "matrix-js-sdk/src/logger"; export class RoomNotificationState extends NotificationState implements IDestroyable { constructor(public readonly room: Room) { @@ -35,7 +36,7 @@ export class RoomNotificationState extends NotificationState implements IDestroy this.room.on("Room.redaction", this.handleRoomEventUpdate); this.room.on("Room.myMembership", this.handleMembershipUpdate); this.room.on("Room.localEchoUpdated", this.handleLocalEchoUpdated); - MatrixClientPeg.get().on("Event.decrypted", this.handleRoomEventUpdate); + MatrixClientPeg.get().on("Event.decrypted", this.onEventDecrypted); MatrixClientPeg.get().on("accountData", this.handleAccountDataUpdate); this.updateNotificationState(); } @@ -52,7 +53,7 @@ export class RoomNotificationState extends NotificationState implements IDestroy this.room.removeListener("Room.myMembership", this.handleMembershipUpdate); this.room.removeListener("Room.localEchoUpdated", this.handleLocalEchoUpdated); if (MatrixClientPeg.get()) { - MatrixClientPeg.get().removeListener("Event.decrypted", this.handleRoomEventUpdate); + MatrixClientPeg.get().removeListener("Event.decrypted", this.onDecrypt); MatrixClientPeg.get().removeListener("accountData", this.handleAccountDataUpdate); } } @@ -71,8 +72,15 @@ export class RoomNotificationState extends NotificationState implements IDestroy this.updateNotificationState(); }; + private onEventDecrypted = (event: MatrixEvent) => { + if (event.getRoomId() !== this.room.roomId) return; // ignore - not for us or notifications timeline + + this.updateNotificationState(); + }; + private handleRoomEventUpdate = (event: MatrixEvent, room: Room | null) => { if (room?.roomId !== this.room.roomId) return; // ignore - not for us or notifications timeline + this.updateNotificationState(); }; From 1713f99749475eb463c14d25d99835d5acfac4aa Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 15 Feb 2022 19:52:40 +0000 Subject: [PATCH 2/3] Remove unused import --- src/stores/notifications/RoomNotificationState.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stores/notifications/RoomNotificationState.ts b/src/stores/notifications/RoomNotificationState.ts index 9d5e65d6c9c..ff3f2f1f271 100644 --- a/src/stores/notifications/RoomNotificationState.ts +++ b/src/stores/notifications/RoomNotificationState.ts @@ -26,7 +26,6 @@ import * as RoomNotifs from '../../RoomNotifs'; import * as Unread from '../../Unread'; import { NotificationState } from "./NotificationState"; import { getUnsentMessages } from "../../components/structures/RoomStatusBar"; -import { logger } from "matrix-js-sdk/src/logger"; export class RoomNotificationState extends NotificationState implements IDestroyable { constructor(public readonly room: Room) { From 1d28e4b42256e00abfe31b968e7c3f5e6aae556e Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 15 Feb 2022 19:55:06 +0000 Subject: [PATCH 3/3] Fix listener removal --- src/stores/notifications/RoomNotificationState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/notifications/RoomNotificationState.ts b/src/stores/notifications/RoomNotificationState.ts index ff3f2f1f271..1b68f3a7b4b 100644 --- a/src/stores/notifications/RoomNotificationState.ts +++ b/src/stores/notifications/RoomNotificationState.ts @@ -52,7 +52,7 @@ export class RoomNotificationState extends NotificationState implements IDestroy this.room.removeListener("Room.myMembership", this.handleMembershipUpdate); this.room.removeListener("Room.localEchoUpdated", this.handleLocalEchoUpdated); if (MatrixClientPeg.get()) { - MatrixClientPeg.get().removeListener("Event.decrypted", this.onDecrypt); + MatrixClientPeg.get().removeListener("Event.decrypted", this.onEventDecrypted); MatrixClientPeg.get().removeListener("accountData", this.handleAccountDataUpdate); } }