From d6d327c760aaf20ba55d901a0b3f3d511af0f8c8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 7 Dec 2022 15:48:32 -0600 Subject: [PATCH] Helmet: add unread chats count --- app/soapbox/components/helmet.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/soapbox/components/helmet.tsx b/app/soapbox/components/helmet.tsx index 23a73e744..6fa678a04 100644 --- a/app/soapbox/components/helmet.tsx +++ b/app/soapbox/components/helmet.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Helmet as ReactHelmet } from 'react-helmet'; +import { useStatContext } from 'soapbox/contexts/stat-context'; import { useAppSelector, useInstance, useSettings } from 'soapbox/hooks'; import { RootState } from 'soapbox/store'; import FaviconService from 'soapbox/utils/favicon-service'; @@ -9,15 +10,15 @@ FaviconService.initFaviconService(); const getNotifTotals = (state: RootState): number => { const notifications = state.notifications.unread || 0; - const chats = state.chats.items.reduce((acc: any, curr: any) => acc + Math.min(curr.get('unread', 0), 1), 0); const reports = state.admin.openReports.count(); const approvals = state.admin.awaitingApproval.count(); - return notifications + chats + reports + approvals; + return notifications + reports + approvals; }; const Helmet: React.FC = ({ children }) => { const instance = useInstance(); - const unreadCount = useAppSelector((state) => getNotifTotals(state)); + const { unreadChatsCount } = useStatContext(); + const unreadCount = useAppSelector((state) => getNotifTotals(state) + unreadChatsCount); const demetricator = useSettings().get('demetricator'); const hasUnreadNotifications = React.useMemo(() => !(unreadCount < 1 || demetricator), [unreadCount, demetricator]);