Fix wrong notification count
authorAjay Bura <32841439+ajbura@users.noreply.github.com>
Tue, 6 Sep 2022 08:52:56 +0000 (14:22 +0530)
committerAjay Bura <32841439+ajbura@users.noreply.github.com>
Tue, 6 Sep 2022 08:52:56 +0000 (14:22 +0530)
src/app/organisms/navigation/DrawerBreadcrumb.jsx
src/client/state/Notifications.js

index be5b345bf26fc75019c506d77531840d2db7035a..face349d48c0ff29d4997025f930b0bc847bf132 100644 (file)
@@ -21,7 +21,7 @@ import ChevronRightIC from '../../../../public/res/ic/outlined/chevron-right.svg
 function DrawerBreadcrumb({ spaceId }) {
   const [, forceUpdate] = useState({});
   const scrollRef = useRef(null);
-  const { roomList, notifications } = initMatrix;
+  const { roomList, notifications, accountData } = initMatrix;
   const mx = initMatrix.matrixClient;
   const spacePath = navigation.selectedSpacePath;
 
@@ -49,9 +49,9 @@ function DrawerBreadcrumb({ spaceId }) {
   }, [spaceId]);
 
   function getHomeNotiExcept(childId) {
-    const orphans = roomList.getOrphans();
-    const childIndex = orphans.indexOf(childId);
-    if (childId !== -1) orphans.splice(childIndex, 1);
+    const orphans = roomList.getOrphans()
+      .filter((id) => (id !== childId))
+      .filter((id) => !accountData.spaceShortcut.has(id));
 
     let noti = null;
 
index 90f9b4ad865b188e9fd2585feb3257ce43133b58..309c322ae00fc463f7b679f3c84a595d6ead00d5 100644 (file)
@@ -114,8 +114,7 @@ class Notifications extends EventEmitter {
   }
 
   getTotalNoti(roomId) {
-    const { total, highlight } = this.getNoti(roomId);
-    if (highlight > total) return highlight;
+    const { total } = this.getNoti(roomId);
     return total;
   }
 
@@ -166,7 +165,7 @@ class Notifications extends EventEmitter {
 
   _setNoti(roomId, total, highlight) {
     const addNoti = (id, t, h, fromId) => {
-      const prevTotal = this.roomIdToNoti.get(id)?.total ?? null;
+      const prevTotal = this.roomIdToNoti.has(id) ? this.getT : null;
       const noti = this.getNoti(id);
 
       noti.total += t;
@@ -181,7 +180,7 @@ class Notifications extends EventEmitter {
     };
 
     const noti = this.getNoti(roomId);
-    const addT = total - noti.total;
+    const addT = (highlight > total ? highlight : total) - noti.total;
     const addH = highlight - noti.highlight;
     if (addT < 0 || addH < 0) return;