Fix getAllParent including itself

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-14 17:31:57 +05:30
parent 5e9b45ad5f
commit fe18611b4b
2 changed files with 7 additions and 8 deletions

View file

@ -117,7 +117,7 @@ class Notifications extends EventEmitter {
if (addT < 0 || addH < 0) return; if (addT < 0 || addH < 0) return;
addNoti(roomId, addT, addH); addNoti(roomId, addT, addH);
const allParentSpaces = this.roomList.getParentSpaces(roomId); const allParentSpaces = this.roomList.getAllParentSpaces(roomId);
allParentSpaces.forEach((spaceId) => { allParentSpaces.forEach((spaceId) => {
addNoti(spaceId, addT, addH, roomId); addNoti(spaceId, addT, addH, roomId);
}); });
@ -149,7 +149,7 @@ class Notifications extends EventEmitter {
}; };
removeNoti(roomId, total, highlight); removeNoti(roomId, total, highlight);
const allParentSpaces = this.roomList.getParentSpaces(roomId); const allParentSpaces = this.roomList.getAllParentSpaces(roomId);
allParentSpaces.forEach((spaceId) => { allParentSpaces.forEach((spaceId) => {
removeNoti(spaceId, total, highlight, roomId); removeNoti(spaceId, total, highlight, roomId);
}); });

View file

@ -91,21 +91,20 @@ class RoomList extends EventEmitter {
if (parents.size === 0) this.roomIdToParents.delete(roomId); if (parents.size === 0) this.roomIdToParents.delete(roomId);
} }
getParentSpaces(roomId) { getAllParentSpaces(roomId) {
const allParents = new Set(); const allParents = new Set();
const processed = new Set();
const addAllParentIds = (rId) => { const addAllParentIds = (rId) => {
if (processed.has(rId)) return; if (allParents.has(rId)) return;
processed.add(rId); allParents.add(rId);
const parents = this.roomIdToParents.get(rId); const parents = this.roomIdToParents.get(rId);
if (parents === undefined) return; if (parents === undefined) return;
parents.forEach((id) => allParents.add(id));
parents.forEach((id) => addAllParentIds(id)); parents.forEach((id) => addAllParentIds(id));
}; };
addAllParentIds(roomId); addAllParentIds(roomId);
processed.clear(); allParents.delete(roomId);
return allParents; return allParents;
} }