diff --git a/lib/hooks/child-threads.js b/lib/hooks/child-threads.js --- a/lib/hooks/child-threads.js +++ b/lib/hooks/child-threads.js @@ -12,7 +12,7 @@ } from '../selectors/chat-selectors.js'; import { useGlobalThreadSearchIndex } from '../selectors/nav-selectors.js'; import { childThreadInfos } from '../selectors/thread-selectors.js'; -import { threadInChatList } from '../shared/thread-utils.js'; +import { useThreadsInChatList } from '../shared/thread-utils.js'; import threadWatcher from '../shared/thread-watcher.js'; import type { ThreadInfo, @@ -63,14 +63,25 @@ const searchTextExists = !!searchText.length; + const subchannelsInChatListThreadInfos = allSubchannelsList.map( + item => item.threadInfo, + ); + const subchannelsInChatList = useThreadsInChatList( + subchannelsInChatListThreadInfos, + ); + const subchannelIDsInChatList = React.useMemo( + () => new Set(subchannelsInChatList.map(thread => thread.id)), + [subchannelsInChatList], + ); + const subchannelIDsNotInChatList = React.useMemo( () => new Set( allSubchannelsList - .filter(item => !threadInChatList(item.threadInfo)) + .filter(item => !subchannelIDsInChatList.has(item.threadInfo.id)) .map(item => item.threadInfo.id), ), - [allSubchannelsList], + [allSubchannelsList, subchannelIDsInChatList], ); React.useEffect(() => { diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -221,6 +221,19 @@ ); } +function useThreadsInChatList( + threadInfos: $ReadOnlyArray, +): $ReadOnlyArray { + const visibleThreads = useThreadsWithPermission( + threadInfos, + threadPermissions.VISIBLE, + ); + return React.useMemo( + () => visibleThreads.filter(viewerIsMember), + [visibleThreads], + ); +} + function threadIsTopLevel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return threadInChatList(threadInfo) && threadIsChannel(threadInfo); } @@ -1948,6 +1961,7 @@ viewerIsMember, threadInChatList, useThreadInChatList, + useThreadsInChatList, threadIsTopLevel, threadIsChannel, threadIsSidebar,