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';
|
2023-08-14 23:28:47 +00:00
|
|
|
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-14 23:28:47 +00:00
|
|
|
|
2023-08-21 20:12:27 +00:00
|
|
|
export const getOtherTabsUnreadStats = createSelector(
|
|
|
|
getSelectedNavTab,
|
2023-08-14 23:28:47 +00:00
|
|
|
getAllConversationsUnreadStats,
|
2023-08-21 20:12:27 +00:00
|
|
|
getCallHistoryUnreadCount,
|
2023-08-14 23:28:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-08-14 23:28:47 +00:00
|
|
|
return {
|
2023-08-21 20:12:27 +00:00
|
|
|
unreadCount,
|
|
|
|
unreadMentionsCount,
|
|
|
|
markedUnread,
|
2023-08-14 23:28:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|