diff --git a/lib/selectors/nav-selectors.js b/lib/selectors/nav-selectors.js --- a/lib/selectors/nav-selectors.js +++ b/lib/selectors/nav-selectors.js @@ -3,6 +3,7 @@ import * as React from 'react'; import { createSelector } from 'reselect'; +import { useENSNames } from '../hooks/ens-cache'; import SearchIndex from '../shared/search-index'; import { memberHasAdminPowers } from '../shared/thread-utils'; import type { Platform } from '../types/device-types'; @@ -74,6 +75,37 @@ const viewerID = useSelector( state => state.currentUserInfo && state.currentUserInfo.id, ); + const nonViewerMembers = React.useMemo(() => { + const allMembersOfAllThreads = new Map(); + for (const threadInfo of threadInfos) { + for (const member of threadInfo.members) { + const isParentAdmin = memberHasAdminPowers(member); + if (!member.role && !isParentAdmin) { + continue; + } + if (member.id === viewerID) { + continue; + } + if (!allMembersOfAllThreads.has(member.id)) { + const userInfo = userInfos[member.id]; + if (userInfo?.username) { + allMembersOfAllThreads.set(member.id, userInfo); + } + } + } + } + return [...allMembersOfAllThreads.values()]; + }, [threadInfos, userInfos, viewerID]); + + const nonViewerMembersWithENSNames = useENSNames(nonViewerMembers); + const memberMap = React.useMemo(() => { + const result = new Map(); + for (const userInfo of nonViewerMembersWithENSNames) { + result.set(userInfo.id, userInfo); + } + return result; + }, [nonViewerMembersWithENSNames]); + return React.useMemo(() => { const searchIndex = new SearchIndex(); for (const threadInfo of threadInfos) { @@ -92,15 +124,15 @@ if (member.id === viewerID) { continue; } - const userInfo = userInfos[member.id]; - if (userInfo && userInfo.username) { + const userInfo = memberMap.get(member.id); + if (userInfo?.username) { searchTextArray.push(userInfo.username); } } searchIndex.addEntry(threadInfo.id, searchTextArray.join(' ')); } return searchIndex; - }, [threadInfos, userInfos, viewerID]); + }, [threadInfos, viewerID, memberMap]); } function useGlobalThreadSearchIndex(): SearchIndex {