initNewsItemCountNotification: async()

in src/js/popup/popup.js [837:889]


          initNewsItemCountNotification: async () => {
            
            const localStorage = await browser.storage.local.get();

            const unreadNewsItemsCountExists =
              Object.prototype.hasOwnProperty.call(
                localStorage,
                "unreadNewsItemsCount"
              );
              
            const readNewsItemsCountExists =
              Object.prototype.hasOwnProperty.call(
                localStorage,
                "readNewsItemCount"
              );

            // First-run user: No unread data present
            if (!unreadNewsItemsCountExists && !readNewsItemsCountExists) {
              await browser.storage.local.set({
                unreadNewsItemsCount: sessionState.newsItemsCount,
                readNewsItemCount: 0,
              });
            }

            // FIXME: The total news item count may differ than what is displayed to the user
            // Example: Three items total but user doesn't have waffle for one news item. 
            // Regardless - update the unreadNews count to match whatever is in state
            await browser.storage.local.set({
              unreadNewsItemsCount: sessionState.newsItemsCount,
            });

            const { readNewsItemCount } = await browser.storage.local.get(
              "readNewsItemCount"
            );

            const { unreadNewsItemsCount } = await browser.storage.local.get(
              "unreadNewsItemsCount"
            );

            // Set unread count
            const newsItemCountNotification = document.querySelector(
              ".fx-relay-menu-dashboard-link[data-panel-id='news'] .news-count"
            );
            
            const unreadCount = unreadNewsItemsCount - readNewsItemCount;

            // Show count is it exists
            if (unreadCount > 0) {
              newsItemCountNotification.textContent = unreadCount.toString();
              newsItemCountNotification.classList.remove("is-hidden");
            }
            
          },