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 @@ -43,6 +43,7 @@ import { threadTypes, threadTypeIsCommunityRoot, + type ThreadType, } from '../types/thread-types-enum.js'; import { type ThreadInfo, @@ -463,6 +464,31 @@ baseSavedEmojiAvatarSelectorForThread, ); +const baseThreadInfosSelectorForThreadType = (threadType: ThreadType) => + createSelector( + (state: BaseAppState<>) => threadInfoSelector(state), + (threadInfos: { + +[id: string]: ThreadInfo, + }): $ReadOnlyArray => { + const result = []; + + for (const threadID in threadInfos) { + const threadInfo = threadInfos[threadID]; + if (threadInfo.type === threadType) { + result.push(threadInfo); + } + } + + return result; + }, + ); + +const threadInfosSelectorForThreadType: ( + threadType: ThreadType, +) => (state: BaseAppState<>) => $ReadOnlyArray = _memoize( + baseThreadInfosSelectorForThreadType, +); + export { ancestorThreadInfos, threadInfoSelector, @@ -482,4 +508,5 @@ threadInfoFromSourceMessageIDSelector, pendingToRealizedThreadIDsSelector, savedEmojiAvatarSelectorForThread, + threadInfosSelectorForThreadType, };