Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3527818
D11276.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11276.diff
View Options
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
@@ -1,11 +1,13 @@
// @flow
+import _keyBy from 'lodash/fp/keyBy.js';
+import _mapValues from 'lodash/fp/mapValues.js';
import * as React from 'react';
import { createSelector } from 'reselect';
import { useENSNames } from '../hooks/ens-cache.js';
import SearchIndex from '../shared/search-index.js';
-import { memberHasAdminPowers } from '../shared/thread-utils.js';
+import { roleIsAdminRole } from '../shared/thread-utils.js';
import type { Platform } from '../types/device-types.js';
import {
type CalendarQuery,
@@ -16,9 +18,11 @@
ThreadInfo,
RelativeMemberInfo,
RawThreadInfo,
+ MemberInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { BaseNavInfo } from '../types/nav-types.js';
import type { BaseAppState } from '../types/redux-types.js';
+import { threadTypeIsCommunityRoot } from '../types/thread-types-enum.js';
import type { UserInfo } from '../types/user-types.js';
import { getConfig } from '../utils/config.js';
import { values } from '../utils/objects.js';
@@ -126,11 +130,32 @@
const viewerID = useSelector(
state => state.currentUserInfo && state.currentUserInfo.id,
);
+
+ const communityRootMembersToRole = React.useMemo(() => {
+ const communityThreadInfos = threadInfos.filter(threadInfo =>
+ threadTypeIsCommunityRoot(threadInfo.type),
+ );
+ const communityRoots = _keyBy('id')(communityThreadInfos);
+
+ return _mapValues((threadInfo: ThreadInfo | RawThreadInfo) => {
+ const keyedMembers = _keyBy('id')(threadInfo.members);
+ const keyedMembersToRole = _mapValues(
+ (member: MemberInfo | RelativeMemberInfo) => {
+ return member.role ? threadInfo.roles[member.role] : null;
+ },
+ )(keyedMembers);
+ return keyedMembersToRole;
+ })(communityRoots);
+ }, [threadInfos]);
+
const nonViewerMembers = React.useMemo(() => {
const allMembersOfAllThreads = new Map<string, UserInfo>();
for (const threadInfo of threadInfos) {
for (const member of threadInfo.members) {
- const isParentAdmin = memberHasAdminPowers(member);
+ const communityRole =
+ communityRootMembersToRole[threadInfo.community]?.[member.id];
+ const isParentAdmin = roleIsAdminRole(communityRole);
+
if (!member.role && !isParentAdmin) {
continue;
}
@@ -146,7 +171,7 @@
}
}
return [...allMembersOfAllThreads.values()];
- }, [threadInfos, userInfos, viewerID]);
+ }, [communityRootMembersToRole, threadInfos, userInfos, viewerID]);
const nonViewerMembersWithENSNames = useENSNames(
nonViewerMembers,
@@ -172,7 +197,9 @@
searchTextArray.push(threadInfo.description);
}
for (const member of threadInfo.members) {
- const isParentAdmin = memberHasAdminPowers(member);
+ const communityRole =
+ communityRootMembersToRole[threadInfo.community]?.[member.id];
+ const isParentAdmin = roleIsAdminRole(communityRole);
if (!member.role && !isParentAdmin) {
continue;
}
@@ -193,7 +220,7 @@
searchIndex.addEntry(threadInfo.id, searchTextArray.join(' '));
}
return searchIndex;
- }, [threadInfos, viewerID, userInfos, memberMap]);
+ }, [threadInfos, communityRootMembersToRole, viewerID, userInfos, memberMap]);
}
function useGlobalThreadSearchIndex(): SearchIndex {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 6:54 AM (7 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2701237
Default Alt Text
D11276.diff (3 KB)
Attached To
Mode
D11276: [lib] Remove usage of `memberHasAdminPowers` in `useThreadSearchIndex`
Attached
Detach File
Event Timeline
Log In to Comment