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 @@ -63,6 +63,7 @@ type ThreadRolePermissionsBlob, type UserSurfacedPermission, threadPermissionFilterPrefixes, + threadPermissionsDisabledByBlock, } from '../types/thread-permission-types.js'; import { type ThreadType, @@ -1007,32 +1008,19 @@ return invalidated; } -const permissionsDisabledByBlockArray = [ - threadPermissions.VOICED, - threadPermissions.EDIT_ENTRIES, - threadPermissions.EDIT_THREAD_NAME, - threadPermissions.EDIT_THREAD_COLOR, - threadPermissions.EDIT_THREAD_DESCRIPTION, - threadPermissions.CREATE_SUBCHANNELS, - threadPermissions.CREATE_SIDEBARS, - threadPermissions.JOIN_THREAD, - threadPermissions.EDIT_PERMISSIONS, - threadPermissions.ADD_MEMBERS, - threadPermissions.REMOVE_MEMBERS, -]; - const permissionsDisabledByBlock: Set = new Set( - permissionsDisabledByBlockArray, + values(threadPermissionsDisabledByBlock), ); -const disabledPermissions: ThreadPermissionsInfo = - permissionsDisabledByBlockArray.reduce( - (permissions: ThreadPermissionsInfo, permission: string) => ({ - ...permissions, - [permission]: { value: false, source: null }, - }), - {}, - ); +const disabledPermissions: ThreadPermissionsInfo = values( + threadPermissionsDisabledByBlock, +).reduce( + (permissions: ThreadPermissionsInfo, permission: string) => ({ + ...permissions, + [permission]: { value: false, source: null }, + }), + {}, +); // Consider updating itemHeight in native/chat/chat-thread-list.react.js // if you change this diff --git a/lib/types/thread-permission-types.js b/lib/types/thread-permission-types.js --- a/lib/types/thread-permission-types.js +++ b/lib/types/thread-permission-types.js @@ -6,25 +6,29 @@ import { values } from '../utils/objects.js'; import { tBool, tShape, tID } from '../utils/validation-utils.js'; -// When a new permission is added, if it should be configurable for a role, it -// should be either added to an existing set or a new set alongside a -// new user-facing permission. If it is a permission that should be ensured -// across all roles, it should be added to `universalCommunityPermissions`. -export const threadPermissions = Object.freeze({ - KNOW_OF: 'know_of', - VISIBLE: 'visible', +export const threadPermissionsDisabledByBlock = Object.freeze({ VOICED: 'voiced', EDIT_ENTRIES: 'edit_entries', EDIT_THREAD_NAME: 'edit_thread', EDIT_THREAD_DESCRIPTION: 'edit_thread_description', EDIT_THREAD_COLOR: 'edit_thread_color', - DELETE_THREAD: 'delete_thread', CREATE_SUBCHANNELS: 'create_subthreads', CREATE_SIDEBARS: 'create_sidebars', JOIN_THREAD: 'join_thread', EDIT_PERMISSIONS: 'edit_permissions', ADD_MEMBERS: 'add_members', REMOVE_MEMBERS: 'remove_members', +}); + +// When a new permission is added, if it should be configurable for a role, it +// should be either added to an existing set or a new set alongside a +// new user-facing permission. If it is a permission that should be ensured +// across all roles, it should be added to `universalCommunityPermissions`. +export const threadPermissions = Object.freeze({ + ...threadPermissionsDisabledByBlock, + KNOW_OF: 'know_of', + VISIBLE: 'visible', + DELETE_THREAD: 'delete_thread', CHANGE_ROLE: 'change_role', LEAVE_THREAD: 'leave_thread', REACT_TO_MESSAGE: 'react_to_message',