Only count unread stats for other tabs

This commit is contained in:
Jamie Kyle 2023-08-21 13:12:27 -07:00 committed by GitHub
parent 04f716986c
commit 0e19255256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 67 additions and 42 deletions

View file

@ -26,7 +26,7 @@ enum CallsTabSidebarView {
type CallsTabProps = Readonly<{ type CallsTabProps = Readonly<{
activeCall: ActiveCallStateType | undefined; activeCall: ActiveCallStateType | undefined;
allConversations: ReadonlyArray<ConversationType>; allConversations: ReadonlyArray<ConversationType>;
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
getCallHistoryGroupsCount: ( getCallHistoryGroupsCount: (
options: CallHistoryFilterOptions options: CallHistoryFilterOptions
) => Promise<number>; ) => Promise<number>;
@ -56,7 +56,7 @@ type CallsTabProps = Readonly<{
export function CallsTab({ export function CallsTab({
activeCall, activeCall,
allConversations, allConversations,
appUnreadStats, otherTabsUnreadStats,
getCallHistoryGroupsCount, getCallHistoryGroupsCount,
getCallHistoryGroups, getCallHistoryGroups,
getConversation, getConversation,
@ -158,7 +158,7 @@ export function CallsTab({
? i18n('icu:CallsTab__HeaderTitle--CallsList') ? i18n('icu:CallsTab__HeaderTitle--CallsList')
: i18n('icu:CallsTab__HeaderTitle--NewCall') : i18n('icu:CallsTab__HeaderTitle--NewCall')
} }
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}
navTabsCollapsed={navTabsCollapsed} navTabsCollapsed={navTabsCollapsed}

View file

@ -9,7 +9,7 @@ import { WhatsNewLink } from './WhatsNewLink';
import type { UnreadStats } from '../util/countUnreadStats'; import type { UnreadStats } from '../util/countUnreadStats';
type ChatsTabProps = Readonly<{ type ChatsTabProps = Readonly<{
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
i18n: LocalizerType; i18n: LocalizerType;
hasPendingUpdate: boolean; hasPendingUpdate: boolean;
hasFailedStorySends: boolean; hasFailedStorySends: boolean;
@ -24,7 +24,7 @@ type ChatsTabProps = Readonly<{
}>; }>;
export function ChatsTab({ export function ChatsTab({
appUnreadStats, otherTabsUnreadStats,
i18n, i18n,
hasPendingUpdate, hasPendingUpdate,
hasFailedStorySends, hasFailedStorySends,
@ -41,7 +41,7 @@ export function ChatsTab({
<> <>
<div id="LeftPane"> <div id="LeftPane">
{renderLeftPane({ {renderLeftPane({
appUnreadStats, otherTabsUnreadStats,
collapsed: navTabsCollapsed, collapsed: navTabsCollapsed,
hasPendingUpdate, hasPendingUpdate,
hasFailedStorySends, hasFailedStorySends,

View file

@ -133,7 +133,7 @@ const useProps = (overrideProps: OverridePropsType = {}): PropsType => {
); );
return { return {
appUnreadStats: { otherTabsUnreadStats: {
unreadCount: 0, unreadCount: 0,
unreadMentionsCount: 0, unreadMentionsCount: 0,
markedUnread: false, markedUnread: false,

View file

@ -60,7 +60,7 @@ export enum LeftPaneMode {
} }
export type PropsType = { export type PropsType = {
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
hasExpiredDialog: boolean; hasExpiredDialog: boolean;
hasFailedStorySends: boolean; hasFailedStorySends: boolean;
hasNetworkDialog: boolean; hasNetworkDialog: boolean;
@ -158,7 +158,7 @@ export type PropsType = {
} & LookupConversationWithoutServiceIdActionsType; } & LookupConversationWithoutServiceIdActionsType;
export function LeftPane({ export function LeftPane({
appUnreadStats, otherTabsUnreadStats,
blockConversation, blockConversation,
challengeStatus, challengeStatus,
clearConversationSearch, clearConversationSearch,
@ -556,7 +556,7 @@ export function LeftPane({
modeSpecificProps.mode === LeftPaneMode.SetGroupMetadata modeSpecificProps.mode === LeftPaneMode.SetGroupMetadata
} }
i18n={i18n} i18n={i18n}
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}
navTabsCollapsed={navTabsCollapsed} navTabsCollapsed={navTabsCollapsed}

View file

@ -24,7 +24,7 @@ import type { UnreadStats } from '../util/countUnreadStats';
export type PropsType = { export type PropsType = {
i18n: LocalizerType; i18n: LocalizerType;
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
hasFailedStorySends: boolean; hasFailedStorySends: boolean;
hasPendingUpdate: boolean; hasPendingUpdate: boolean;
navTabsCollapsed: boolean; navTabsCollapsed: boolean;
@ -46,7 +46,7 @@ export type PropsType = {
export function MyStories({ export function MyStories({
i18n, i18n,
appUnreadStats, otherTabsUnreadStats,
hasFailedStorySends, hasFailedStorySends,
hasPendingUpdate, hasPendingUpdate,
navTabsCollapsed, navTabsCollapsed,
@ -90,7 +90,7 @@ export function MyStories({
<NavSidebar <NavSidebar
i18n={i18n} i18n={i18n}
title={i18n('icu:MyStories__title')} title={i18n('icu:MyStories__title')}
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}
navTabsCollapsed={navTabsCollapsed} navTabsCollapsed={navTabsCollapsed}

View file

@ -54,7 +54,7 @@ export type NavSidebarProps = Readonly<{
requiresFullWidth: boolean; requiresFullWidth: boolean;
savePreferredLeftPaneWidth: (width: number) => void; savePreferredLeftPaneWidth: (width: number) => void;
title: string; title: string;
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
}>; }>;
enum DragState { enum DragState {
@ -77,7 +77,7 @@ export function NavSidebar({
requiresFullWidth, requiresFullWidth,
savePreferredLeftPaneWidth, savePreferredLeftPaneWidth,
title, title,
appUnreadStats, otherTabsUnreadStats,
}: NavSidebarProps): JSX.Element { }: NavSidebarProps): JSX.Element {
const [dragState, setDragState] = useState(DragState.INITIAL); const [dragState, setDragState] = useState(DragState.INITIAL);
@ -164,7 +164,7 @@ export function NavSidebar({
onToggleNavTabsCollapse={onToggleNavTabsCollapse} onToggleNavTabsCollapse={onToggleNavTabsCollapse}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
/> />
)} )}
<div <div

View file

@ -117,7 +117,7 @@ function NavTabsItem({
} }
export type NavTabPanelProps = Readonly<{ export type NavTabPanelProps = Readonly<{
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
collapsed: boolean; collapsed: boolean;
hasFailedStorySends: boolean; hasFailedStorySends: boolean;
hasPendingUpdate: boolean; hasPendingUpdate: boolean;
@ -125,7 +125,7 @@ export type NavTabPanelProps = Readonly<{
}>; }>;
export type NavTabsToggleProps = Readonly<{ export type NavTabsToggleProps = Readonly<{
appUnreadStats: UnreadStats | null; otherTabsUnreadStats: UnreadStats | null;
i18n: LocalizerType; i18n: LocalizerType;
hasFailedStorySends: boolean; hasFailedStorySends: boolean;
hasPendingUpdate: boolean; hasPendingUpdate: boolean;
@ -138,7 +138,7 @@ export function NavTabsToggle({
hasFailedStorySends, hasFailedStorySends,
hasPendingUpdate, hasPendingUpdate,
navTabsCollapsed, navTabsCollapsed,
appUnreadStats, otherTabsUnreadStats,
onToggleNavTabsCollapse, onToggleNavTabsCollapse,
}: NavTabsToggleProps): JSX.Element { }: NavTabsToggleProps): JSX.Element {
function handleToggle() { function handleToggle() {
@ -169,7 +169,7 @@ export function NavTabsToggle({
<span className="NavTabs__ItemLabel">{label}</span> <span className="NavTabs__ItemLabel">{label}</span>
<NavTabsItemBadges <NavTabsItemBadges
i18n={i18n} i18n={i18n}
unreadStats={appUnreadStats} unreadStats={otherTabsUnreadStats}
hasError={hasFailedStorySends} hasError={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}
/> />
@ -245,7 +245,7 @@ export function NavTabs({
// These are all shown elsewhere when nav tabs are shown // These are all shown elsewhere when nav tabs are shown
hasFailedStorySends={false} hasFailedStorySends={false}
hasPendingUpdate={false} hasPendingUpdate={false}
appUnreadStats={null} otherTabsUnreadStats={null}
/> />
<TabList <TabList
className="NavTabs__TabList" className="NavTabs__TabList"

View file

@ -28,7 +28,7 @@ import type { UnreadStats } from '../util/countUnreadStats';
export type PropsType = { export type PropsType = {
addStoryData: AddStoryData; addStoryData: AddStoryData;
appUnreadStats: UnreadStats; otherTabsUnreadStats: UnreadStats;
deleteStoryForEveryone: (story: StoryViewType) => unknown; deleteStoryForEveryone: (story: StoryViewType) => unknown;
getPreferredBadge: PreferredBadgeSelectorType; getPreferredBadge: PreferredBadgeSelectorType;
hasFailedStorySends: boolean; hasFailedStorySends: boolean;
@ -65,7 +65,7 @@ export type PropsType = {
export function StoriesTab({ export function StoriesTab({
addStoryData, addStoryData,
appUnreadStats, otherTabsUnreadStats,
deleteStoryForEveryone, deleteStoryForEveryone,
getPreferredBadge, getPreferredBadge,
hasFailedStorySends, hasFailedStorySends,
@ -111,7 +111,7 @@ export function StoriesTab({
{addStoryData && renderStoryCreator()} {addStoryData && renderStoryCreator()}
{isMyStories && myStories.length ? ( {isMyStories && myStories.length ? (
<MyStories <MyStories
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}
hasViewReceiptSetting={hasViewReceiptSetting} hasViewReceiptSetting={hasViewReceiptSetting}
@ -142,7 +142,7 @@ export function StoriesTab({
preferredLeftPaneWidth={preferredLeftPaneWidth} preferredLeftPaneWidth={preferredLeftPaneWidth}
requiresFullWidth requiresFullWidth
savePreferredLeftPaneWidth={savePreferredLeftPaneWidth} savePreferredLeftPaneWidth={savePreferredLeftPaneWidth}
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
actions={ actions={
<> <>
<StoriesAddStoryButton <StoriesAddStoryButton

View file

@ -3,10 +3,11 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import type { StateType } from '../reducer'; import type { StateType } from '../reducer';
import type { NavStateType } from '../ducks/nav'; import { NavTab, type NavStateType } from '../ducks/nav';
import { getAllConversationsUnreadStats } from './conversations'; import { getAllConversationsUnreadStats } from './conversations';
import { getStoriesNotificationCount } from './stories'; import { getStoriesNotificationCount } from './stories';
import type { UnreadStats } from '../../util/countUnreadStats'; import type { UnreadStats } from '../../util/countUnreadStats';
import { getCallHistoryUnreadCount } from './callHistory';
function getNav(state: StateType): NavStateType { function getNav(state: StateType): NavStateType {
return state.nav; return state.nav;
@ -16,16 +17,40 @@ export const getSelectedNavTab = createSelector(getNav, nav => {
return nav.selectedNavTab; return nav.selectedNavTab;
}); });
export const getAppUnreadStats = createSelector( export const getOtherTabsUnreadStats = createSelector(
getSelectedNavTab,
getAllConversationsUnreadStats, getAllConversationsUnreadStats,
getCallHistoryUnreadCount,
getStoriesNotificationCount, 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 { return {
// Note: Conversation unread stats includes the call history unread count. unreadCount,
unreadCount: unreadMentionsCount,
conversationsUnreadStats.unreadCount + storiesNotificationCount, markedUnread,
unreadMentionsCount: conversationsUnreadStats.unreadMentionsCount,
markedUnread: conversationsUnreadStats.markedUnread,
}; };
} }
); );

View file

@ -29,7 +29,7 @@ import { useCallHistoryActions } from '../ducks/callHistory';
import { getCallHistoryEdition } from '../selectors/callHistory'; import { getCallHistoryEdition } from '../selectors/callHistory';
import { getHasPendingUpdate } from '../selectors/updates'; import { getHasPendingUpdate } from '../selectors/updates';
import { getHasAnyFailedStorySends } from '../selectors/stories'; import { getHasAnyFailedStorySends } from '../selectors/stories';
import { getAppUnreadStats } from '../selectors/nav'; import { getOtherTabsUnreadStats } from '../selectors/nav';
function getCallHistoryFilter( function getCallHistoryFilter(
allConversations: Array<ConversationType>, allConversations: Array<ConversationType>,
@ -96,7 +96,7 @@ export function SmartCallsTab(): JSX.Element {
const hasPendingUpdate = useSelector(getHasPendingUpdate); const hasPendingUpdate = useSelector(getHasPendingUpdate);
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends); const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
const appUnreadStats = useSelector(getAppUnreadStats); const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
const { const {
onOutgoingAudioCallInConversation, onOutgoingAudioCallInConversation,
@ -153,7 +153,7 @@ export function SmartCallsTab(): JSX.Element {
<CallsTab <CallsTab
activeCall={activeCall} activeCall={activeCall}
allConversations={allConversations} allConversations={allConversations}
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
getConversation={getConversation} getConversation={getConversation}
getCallHistoryGroupsCount={getCallHistoryGroupsCount} getCallHistoryGroupsCount={getCallHistoryGroupsCount}
getCallHistoryGroups={getCallHistoryGroups} getCallHistoryGroups={getCallHistoryGroups}

View file

@ -22,7 +22,7 @@ import { getNavTabsCollapsed } from '../selectors/items';
import { useItemsActions } from '../ducks/items'; import { useItemsActions } from '../ducks/items';
import { getHasAnyFailedStorySends } from '../selectors/stories'; import { getHasAnyFailedStorySends } from '../selectors/stories';
import { getHasPendingUpdate } from '../selectors/updates'; import { getHasPendingUpdate } from '../selectors/updates';
import { getAppUnreadStats } from '../selectors/nav'; import { getOtherTabsUnreadStats } from '../selectors/nav';
function renderConversationView() { function renderConversationView() {
return <SmartConversationView />; return <SmartConversationView />;
@ -41,7 +41,7 @@ export function SmartChatsTab(): JSX.Element {
const navTabsCollapsed = useSelector(getNavTabsCollapsed); const navTabsCollapsed = useSelector(getNavTabsCollapsed);
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends); const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
const hasPendingUpdate = useSelector(getHasPendingUpdate); const hasPendingUpdate = useSelector(getHasPendingUpdate);
const appUnreadStats = useSelector(getAppUnreadStats); const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
const { selectedConversationId, targetedMessage, targetedMessageSource } = const { selectedConversationId, targetedMessage, targetedMessageSource } =
useSelector<StateType, ConversationsStateType>( useSelector<StateType, ConversationsStateType>(
@ -144,7 +144,7 @@ export function SmartChatsTab(): JSX.Element {
return ( return (
<ChatsTab <ChatsTab
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
i18n={i18n} i18n={i18n}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate} hasPendingUpdate={hasPendingUpdate}

View file

@ -32,7 +32,7 @@ import { useToastActions } from '../ducks/toast';
import { useAudioPlayerActions } from '../ducks/audioPlayer'; import { useAudioPlayerActions } from '../ducks/audioPlayer';
import { useItemsActions } from '../ducks/items'; import { useItemsActions } from '../ducks/items';
import { getHasPendingUpdate } from '../selectors/updates'; import { getHasPendingUpdate } from '../selectors/updates';
import { getAppUnreadStats } from '../selectors/nav'; import { getOtherTabsUnreadStats } from '../selectors/nav';
function renderStoryCreator(): JSX.Element { function renderStoryCreator(): JSX.Element {
return <SmartStoryCreator />; return <SmartStoryCreator />;
@ -71,7 +71,7 @@ export function SmartStoriesTab(): JSX.Element | null {
const hasViewReceiptSetting = useSelector(getHasStoryViewReceiptSetting); const hasViewReceiptSetting = useSelector(getHasStoryViewReceiptSetting);
const hasPendingUpdate = useSelector(getHasPendingUpdate); const hasPendingUpdate = useSelector(getHasPendingUpdate);
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends); const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
const appUnreadStats = useSelector(getAppUnreadStats); const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
const remoteConfig = useSelector(getRemoteConfig); const remoteConfig = useSelector(getRemoteConfig);
const maxAttachmentSizeInKb = getMaximumAttachmentSizeInKb( const maxAttachmentSizeInKb = getMaximumAttachmentSizeInKb(
@ -98,7 +98,7 @@ export function SmartStoriesTab(): JSX.Element | null {
return ( return (
<StoriesTab <StoriesTab
appUnreadStats={appUnreadStats} otherTabsUnreadStats={otherTabsUnreadStats}
addStoryData={addStoryData} addStoryData={addStoryData}
getPreferredBadge={getPreferredBadge} getPreferredBadge={getPreferredBadge}
hasFailedStorySends={hasFailedStorySends} hasFailedStorySends={hasFailedStorySends}