diff --git a/lib/selectors/thread-selectors.js b/lib/selectors/thread-selectors.js --- a/lib/selectors/thread-selectors.js +++ b/lib/selectors/thread-selectors.js @@ -290,6 +290,27 @@ ).length, ); +const baseUnreadCountSelectorForCommunity: ( + communityID: string, +) => (BaseAppState<>) => number = (communityID: string) => + createSelector( + (state: BaseAppState<>) => state.threadStore.threadInfos, + (threadInfos: RawThreadInfos): number => + Object.values(threadInfos).filter( + threadInfo => + threadInHomeChatList(threadInfo) && + threadInfo.currentUser.unread && + (communityID === threadInfo.community || + communityID === threadInfo.id), + ).length, + ); + +const unreadCountSelectorForCommunity: ( + communityID: string, +) => (state: BaseAppState<>) => number = _memoize( + baseUnreadCountSelectorForCommunity, +); + const baseAncestorThreadInfos: ( threadID: string, ) => (BaseAppState<>) => $ReadOnlyArray = (threadID: string) => @@ -518,6 +539,7 @@ containedThreadInfos, unreadCount, unreadBackgroundCount, + unreadCountSelectorForCommunity, otherUsersButNoOtherAdmins, mostRecentlyReadThread, mostRecentlyReadThreadSelector,