signal-desktop/ts/state/selectors/nav.ts

57 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-08-09 00:53:06 +00:00
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import type { StateType } from '../reducer';
2023-08-21 20:12:27 +00:00
import { NavTab, type NavStateType } from '../ducks/nav';
import { getAllConversationsUnreadStats } from './conversations';
import { getStoriesNotificationCount } from './stories';
import type { UnreadStats } from '../../util/countUnreadStats';
2023-08-21 20:12:27 +00:00
import { getCallHistoryUnreadCount } from './callHistory';
2023-08-09 00:53:06 +00:00
function getNav(state: StateType): NavStateType {
return state.nav;
}
export const getSelectedNavTab = createSelector(getNav, nav => {
return nav.selectedNavTab;
});
2023-08-21 20:12:27 +00:00
export const getOtherTabsUnreadStats = createSelector(
getSelectedNavTab,
getAllConversationsUnreadStats,
2023-08-21 20:12:27 +00:00
getCallHistoryUnreadCount,
getStoriesNotificationCount,
2023-08-21 20:12:27 +00:00
(
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 {
2023-08-21 20:12:27 +00:00
unreadCount,
unreadMentionsCount,
markedUnread,
};
}
);