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 @@ -34,6 +34,7 @@ threadPermissionsFromBitmaskHex, } from '../permissions/minimally-encoded-thread-permissions.js'; import { specialRoles } from '../permissions/special-roles.js'; +import type { SpecialRole } from '../permissions/special-roles.js'; import { permissionLookup, getAllThreadPermissions, @@ -121,7 +122,7 @@ type ThreadEntity, type UserEntity, } from '../utils/entity-text.js'; -import { entries } from '../utils/objects.js'; +import { entries, values } from '../utils/objects.js'; import { useDispatchActionPromise, type DispatchActionPromise, @@ -1699,6 +1700,27 @@ }, [threadInfo]); } +function useRoleNamesToSpecialRole(threadInfo: ThreadInfo): { + +[roleName: string]: ?SpecialRole, +} { + return React.useMemo(() => { + const roleNamesToSpecialRole: { [roleName: string]: ?SpecialRole } = {}; + values(threadInfo.roles).forEach(role => { + if (roleNamesToSpecialRole[role.name] !== undefined) { + return; + } + if (roleIsDefaultRole(role)) { + roleNamesToSpecialRole[role.name] = specialRoles.DEFAULT_ROLE; + } else if (roleIsAdminRole(role)) { + roleNamesToSpecialRole[role.name] = specialRoles.ADMIN_ROLE; + } else { + roleNamesToSpecialRole[role.name] = null; + } + }); + return roleNamesToSpecialRole; + }, [threadInfo.roles]); +} + type RoleUserSurfacedPermissions = { +[roleName: string]: $ReadOnlySet, }; @@ -1888,6 +1910,7 @@ patchThreadInfoToIncludeMentionedMembersOfParent, threadInfoInsideCommunity, useRoleMemberCountsForCommunity, + useRoleNamesToSpecialRole, useRoleUserSurfacedPermissions, getThreadsToDeleteText, useUserProfileThreadInfo, diff --git a/native/roles/community-roles-screen.react.js b/native/roles/community-roles-screen.react.js --- a/native/roles/community-roles-screen.react.js +++ b/native/roles/community-roles-screen.react.js @@ -7,6 +7,7 @@ import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { useRoleMemberCountsForCommunity, + useRoleNamesToSpecialRole, useRoleUserSurfacedPermissions, } from 'lib/shared/thread-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; @@ -51,6 +52,7 @@ const styles = useStyles(unboundStyles); const roleNamesToMembers = useRoleMemberCountsForCommunity(threadInfo); + const roleNamesToSpecialRole = useRoleNamesToSpecialRole(threadInfo); const roleNamesToUserSurfacedPermissions = useRoleUserSurfacedPermissions(threadInfo); @@ -65,6 +67,7 @@ navigation={props.navigation} threadInfo={threadInfo} roleName={roleName} + specialRole={roleNamesToSpecialRole[roleName]} rolePermissions={roleNamesToUserSurfacedPermissions[roleName]} memberCount={roleNamesToMembers[roleName]} />, @@ -76,6 +79,7 @@ roleNamesToMembers, props.navigation, threadInfo, + roleNamesToSpecialRole, roleNamesToUserSurfacedPermissions, ]); diff --git a/native/roles/role-panel-entry.react.js b/native/roles/role-panel-entry.react.js --- a/native/roles/role-panel-entry.react.js +++ b/native/roles/role-panel-entry.react.js @@ -6,6 +6,8 @@ import { Platform, Text, TouchableOpacity, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import type { SpecialRole } from 'lib/permissions/special-roles.js'; +import { specialRoles } from 'lib/permissions/special-roles.js'; import { roleIsDefaultRole } from 'lib/shared/thread-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { UserSurfacedPermission } from 'lib/types/thread-permission-types.js'; @@ -22,13 +24,20 @@ +navigation: RolesNavigationProp<'CommunityRolesScreen'>, +threadInfo: ThreadInfo, +roleName: string, + +specialRole: ?SpecialRole, +rolePermissions: $ReadOnlySet, +memberCount: number, }; function RolePanelEntry(props: RolePanelEntryProps): React.Node { - const { navigation, threadInfo, roleName, rolePermissions, memberCount } = - props; + const { + navigation, + threadInfo, + roleName, + specialRole, + rolePermissions, + memberCount, + } = props; const styles = useStyles(unboundStyles); const existingRoleID = React.useMemo( @@ -128,7 +137,7 @@ ]); const menuButton = React.useMemo(() => { - if (roleName === 'Admins') { + if (specialRole === specialRoles.ADMIN_ROLE) { return ; } return ( @@ -141,10 +150,10 @@ ); }, [ - roleName, - styles.rolePanelEmptyMenuButton, - styles.rolePanelMenuButton, + specialRole, showActionSheet, + styles.rolePanelMenuButton, + styles.rolePanelEmptyMenuButton, ]); return (