diff --git a/ts/components/CallsTab.tsx b/ts/components/CallsTab.tsx index e1a764ec648a..06970f772052 100644 --- a/ts/components/CallsTab.tsx +++ b/ts/components/CallsTab.tsx @@ -26,7 +26,7 @@ enum CallsTabSidebarView { type CallsTabProps = Readonly<{ activeCall: ActiveCallStateType | undefined; allConversations: ReadonlyArray; - appUnreadStats: UnreadStats; + otherTabsUnreadStats: UnreadStats; getCallHistoryGroupsCount: ( options: CallHistoryFilterOptions ) => Promise; @@ -56,7 +56,7 @@ type CallsTabProps = Readonly<{ export function CallsTab({ activeCall, allConversations, - appUnreadStats, + otherTabsUnreadStats, getCallHistoryGroupsCount, getCallHistoryGroups, getConversation, @@ -158,7 +158,7 @@ export function CallsTab({ ? i18n('icu:CallsTab__HeaderTitle--CallsList') : i18n('icu:CallsTab__HeaderTitle--NewCall') } - appUnreadStats={appUnreadStats} + otherTabsUnreadStats={otherTabsUnreadStats} hasFailedStorySends={hasFailedStorySends} hasPendingUpdate={hasPendingUpdate} navTabsCollapsed={navTabsCollapsed} diff --git a/ts/components/ChatsTab.tsx b/ts/components/ChatsTab.tsx index 43ad9ebf8781..f9bc40cfea1d 100644 --- a/ts/components/ChatsTab.tsx +++ b/ts/components/ChatsTab.tsx @@ -9,7 +9,7 @@ import { WhatsNewLink } from './WhatsNewLink'; import type { UnreadStats } from '../util/countUnreadStats'; type ChatsTabProps = Readonly<{ - appUnreadStats: UnreadStats; + otherTabsUnreadStats: UnreadStats; i18n: LocalizerType; hasPendingUpdate: boolean; hasFailedStorySends: boolean; @@ -24,7 +24,7 @@ type ChatsTabProps = Readonly<{ }>; export function ChatsTab({ - appUnreadStats, + otherTabsUnreadStats, i18n, hasPendingUpdate, hasFailedStorySends, @@ -41,7 +41,7 @@ export function ChatsTab({ <>
{renderLeftPane({ - appUnreadStats, + otherTabsUnreadStats, collapsed: navTabsCollapsed, hasPendingUpdate, hasFailedStorySends, diff --git a/ts/components/LeftPane.stories.tsx b/ts/components/LeftPane.stories.tsx index 4b8276fdc2fd..3b95675eef77 100644 --- a/ts/components/LeftPane.stories.tsx +++ b/ts/components/LeftPane.stories.tsx @@ -133,7 +133,7 @@ const useProps = (overrideProps: OverridePropsType = {}): PropsType => { ); return { - appUnreadStats: { + otherTabsUnreadStats: { unreadCount: 0, unreadMentionsCount: 0, markedUnread: false, diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 4412dcbfd2a9..0ecaa6017bec 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -60,7 +60,7 @@ export enum LeftPaneMode { } export type PropsType = { - appUnreadStats: UnreadStats; + otherTabsUnreadStats: UnreadStats; hasExpiredDialog: boolean; hasFailedStorySends: boolean; hasNetworkDialog: boolean; @@ -158,7 +158,7 @@ export type PropsType = { } & LookupConversationWithoutServiceIdActionsType; export function LeftPane({ - appUnreadStats, + otherTabsUnreadStats, blockConversation, challengeStatus, clearConversationSearch, @@ -556,7 +556,7 @@ export function LeftPane({ modeSpecificProps.mode === LeftPaneMode.SetGroupMetadata } i18n={i18n} - appUnreadStats={appUnreadStats} + otherTabsUnreadStats={otherTabsUnreadStats} hasFailedStorySends={hasFailedStorySends} hasPendingUpdate={hasPendingUpdate} navTabsCollapsed={navTabsCollapsed} diff --git a/ts/components/MyStories.tsx b/ts/components/MyStories.tsx index 4ebc44d5b22a..51c94e64d3d8 100644 --- a/ts/components/MyStories.tsx +++ b/ts/components/MyStories.tsx @@ -24,7 +24,7 @@ import type { UnreadStats } from '../util/countUnreadStats'; export type PropsType = { i18n: LocalizerType; - appUnreadStats: UnreadStats; + otherTabsUnreadStats: UnreadStats; hasFailedStorySends: boolean; hasPendingUpdate: boolean; navTabsCollapsed: boolean; @@ -46,7 +46,7 @@ export type PropsType = { export function MyStories({ i18n, - appUnreadStats, + otherTabsUnreadStats, hasFailedStorySends, hasPendingUpdate, navTabsCollapsed, @@ -90,7 +90,7 @@ export function MyStories({ void; title: string; - appUnreadStats: UnreadStats; + otherTabsUnreadStats: UnreadStats; }>; enum DragState { @@ -77,7 +77,7 @@ export function NavSidebar({ requiresFullWidth, savePreferredLeftPaneWidth, title, - appUnreadStats, + otherTabsUnreadStats, }: NavSidebarProps): JSX.Element { const [dragState, setDragState] = useState(DragState.INITIAL); @@ -164,7 +164,7 @@ export function NavSidebar({ onToggleNavTabsCollapse={onToggleNavTabsCollapse} hasFailedStorySends={hasFailedStorySends} hasPendingUpdate={hasPendingUpdate} - appUnreadStats={appUnreadStats} + otherTabsUnreadStats={otherTabsUnreadStats} /> )}
; export type NavTabsToggleProps = Readonly<{ - appUnreadStats: UnreadStats | null; + otherTabsUnreadStats: UnreadStats | null; i18n: LocalizerType; hasFailedStorySends: boolean; hasPendingUpdate: boolean; @@ -138,7 +138,7 @@ export function NavTabsToggle({ hasFailedStorySends, hasPendingUpdate, navTabsCollapsed, - appUnreadStats, + otherTabsUnreadStats, onToggleNavTabsCollapse, }: NavTabsToggleProps): JSX.Element { function handleToggle() { @@ -169,7 +169,7 @@ export function NavTabsToggle({ {label} @@ -245,7 +245,7 @@ export function NavTabs({ // These are all shown elsewhere when nav tabs are shown hasFailedStorySends={false} hasPendingUpdate={false} - appUnreadStats={null} + otherTabsUnreadStats={null} /> unknown; getPreferredBadge: PreferredBadgeSelectorType; hasFailedStorySends: boolean; @@ -65,7 +65,7 @@ export type PropsType = { export function StoriesTab({ addStoryData, - appUnreadStats, + otherTabsUnreadStats, deleteStoryForEveryone, getPreferredBadge, hasFailedStorySends, @@ -111,7 +111,7 @@ export function StoriesTab({ {addStoryData && renderStoryCreator()} {isMyStories && myStories.length ? ( { return nav.selectedNavTab; }); -export const getAppUnreadStats = createSelector( +export const getOtherTabsUnreadStats = createSelector( + getSelectedNavTab, getAllConversationsUnreadStats, + getCallHistoryUnreadCount, getStoriesNotificationCount, - (conversationsUnreadStats, storiesNotificationCount): UnreadStats => { + ( + selectedNavTab, + conversationsUnreadStats, + callHistoryUnreadCount, + storiesNotificationCount + ): UnreadStats => { + let unreadCount = 0; + let unreadMentionsCount = 0; + let markedUnread = false; + + if (selectedNavTab !== NavTab.Chats) { + unreadCount += conversationsUnreadStats.unreadCount; + unreadMentionsCount += conversationsUnreadStats.unreadMentionsCount; + markedUnread ||= conversationsUnreadStats.markedUnread; + } + + // Note: Conversation unread stats includes the call history unread count. + if (selectedNavTab !== NavTab.Calls) { + unreadCount += callHistoryUnreadCount; + } + + if (selectedNavTab !== NavTab.Stories) { + unreadCount += storiesNotificationCount; + } + return { - // Note: Conversation unread stats includes the call history unread count. - unreadCount: - conversationsUnreadStats.unreadCount + storiesNotificationCount, - unreadMentionsCount: conversationsUnreadStats.unreadMentionsCount, - markedUnread: conversationsUnreadStats.markedUnread, + unreadCount, + unreadMentionsCount, + markedUnread, }; } ); diff --git a/ts/state/smart/CallsTab.tsx b/ts/state/smart/CallsTab.tsx index 8995367087f2..a8e9a50ca7e0 100644 --- a/ts/state/smart/CallsTab.tsx +++ b/ts/state/smart/CallsTab.tsx @@ -29,7 +29,7 @@ import { useCallHistoryActions } from '../ducks/callHistory'; import { getCallHistoryEdition } from '../selectors/callHistory'; import { getHasPendingUpdate } from '../selectors/updates'; import { getHasAnyFailedStorySends } from '../selectors/stories'; -import { getAppUnreadStats } from '../selectors/nav'; +import { getOtherTabsUnreadStats } from '../selectors/nav'; function getCallHistoryFilter( allConversations: Array, @@ -96,7 +96,7 @@ export function SmartCallsTab(): JSX.Element { const hasPendingUpdate = useSelector(getHasPendingUpdate); const hasFailedStorySends = useSelector(getHasAnyFailedStorySends); - const appUnreadStats = useSelector(getAppUnreadStats); + const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats); const { onOutgoingAudioCallInConversation, @@ -153,7 +153,7 @@ export function SmartCallsTab(): JSX.Element { ; @@ -41,7 +41,7 @@ export function SmartChatsTab(): JSX.Element { const navTabsCollapsed = useSelector(getNavTabsCollapsed); const hasFailedStorySends = useSelector(getHasAnyFailedStorySends); const hasPendingUpdate = useSelector(getHasPendingUpdate); - const appUnreadStats = useSelector(getAppUnreadStats); + const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats); const { selectedConversationId, targetedMessage, targetedMessageSource } = useSelector( @@ -144,7 +144,7 @@ export function SmartChatsTab(): JSX.Element { return ( ; @@ -71,7 +71,7 @@ export function SmartStoriesTab(): JSX.Element | null { const hasViewReceiptSetting = useSelector(getHasStoryViewReceiptSetting); const hasPendingUpdate = useSelector(getHasPendingUpdate); const hasFailedStorySends = useSelector(getHasAnyFailedStorySends); - const appUnreadStats = useSelector(getAppUnreadStats); + const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats); const remoteConfig = useSelector(getRemoteConfig); const maxAttachmentSizeInKb = getMaximumAttachmentSizeInKb( @@ -98,7 +98,7 @@ export function SmartStoriesTab(): JSX.Element | null { return (