From fe18611b4bdc24d3f1b6128707f1fecd7c7d8066 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Mon, 14 Mar 2022 17:31:57 +0530 Subject: [PATCH] Fix getAllParent including itself Signed-off-by: Ajay Bura --- src/client/state/Notifications.js | 4 ++-- src/client/state/RoomList.js | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/client/state/Notifications.js b/src/client/state/Notifications.js index 1f7be3e..8ede169 100644 --- a/src/client/state/Notifications.js +++ b/src/client/state/Notifications.js @@ -117,7 +117,7 @@ class Notifications extends EventEmitter { if (addT < 0 || addH < 0) return; addNoti(roomId, addT, addH); - const allParentSpaces = this.roomList.getParentSpaces(roomId); + const allParentSpaces = this.roomList.getAllParentSpaces(roomId); allParentSpaces.forEach((spaceId) => { addNoti(spaceId, addT, addH, roomId); }); @@ -149,7 +149,7 @@ class Notifications extends EventEmitter { }; removeNoti(roomId, total, highlight); - const allParentSpaces = this.roomList.getParentSpaces(roomId); + const allParentSpaces = this.roomList.getAllParentSpaces(roomId); allParentSpaces.forEach((spaceId) => { removeNoti(spaceId, total, highlight, roomId); }); diff --git a/src/client/state/RoomList.js b/src/client/state/RoomList.js index e200aac..ec3c060 100644 --- a/src/client/state/RoomList.js +++ b/src/client/state/RoomList.js @@ -91,21 +91,20 @@ class RoomList extends EventEmitter { if (parents.size === 0) this.roomIdToParents.delete(roomId); } - getParentSpaces(roomId) { + getAllParentSpaces(roomId) { const allParents = new Set(); - const processed = new Set(); + const addAllParentIds = (rId) => { - if (processed.has(rId)) return; - processed.add(rId); + if (allParents.has(rId)) return; + allParents.add(rId); const parents = this.roomIdToParents.get(rId); if (parents === undefined) return; - parents.forEach((id) => allParents.add(id)); parents.forEach((id) => addAllParentIds(id)); }; addAllParentIds(roomId); - processed.clear(); + allParents.delete(roomId); return allParents; }