diff --git a/lib/permissions/thread-permissions.js b/lib/permissions/thread-permissions.js --- a/lib/permissions/thread-permissions.js +++ b/lib/permissions/thread-permissions.js @@ -23,8 +23,13 @@ } from '../types/thread-permission-types.js'; import { type ThreadType, + type ThinThreadType, + type ThickThreadType, threadTypes, threadTypeIsAnnouncementThread, + threadTypeIsThick, + assertThickThreadType, + assertThinThreadType, } from '../types/thread-types-enum.js'; function permissionLookup( @@ -188,7 +193,7 @@ function getThreadPermissionBlobFromUserSurfacedPermissions( communityUserSurfacedPermissions: $ReadOnlyArray, - threadType: ThreadType, + threadType: ThinThreadType, ): ThreadRolePermissionsBlob { const mappedUserSurfacedPermissions = communityUserSurfacedPermissions .map(permission => [...configurableCommunityPermissions[permission]]) @@ -230,7 +235,7 @@ ]; function getRolePermissionBlobsForCommunityRoot( - threadType: ThreadType, + threadType: ThinThreadType, ): RolePermissionBlobs { let memberUserSurfacedPermissions; if (threadType === threadTypes.GENESIS) { @@ -350,7 +355,17 @@ }; function getRolePermissionBlobs(threadType: ThreadType): RolePermissionBlobs { - if (threadType === threadTypes.SIDEBAR) { + if (threadTypeIsThick(threadType)) { + const thickThreadType = assertThickThreadType(threadType); + const memberPermissions = + getThickThreadRolePermissionsBlob(thickThreadType); + return { + Members: memberPermissions, + }; + } + const thinThreadType = assertThinThreadType(threadType); + + if (thinThreadType === threadTypes.SIDEBAR) { const memberPermissions = { [threadPermissions.VOICED]: true, [threadPermissions.REACT_TO_MESSAGE]: true, @@ -373,7 +388,7 @@ const openDescendantVisible = OPEN_DESCENDANT + threadPermissions.VISIBLE; const openChildJoinThread = OPEN_CHILD + threadPermissions.JOIN_THREAD; - if (threadType === threadTypes.GENESIS_PRIVATE) { + if (thinThreadType === threadTypes.GENESIS_PRIVATE) { const memberPermissions = { [threadPermissions.KNOW_OF]: true, [threadPermissions.VISIBLE]: true, @@ -393,7 +408,7 @@ }; } - if (threadType === threadTypes.GENESIS_PERSONAL) { + if (thinThreadType === threadTypes.GENESIS_PERSONAL) { return { Members: { [threadPermissions.KNOW_OF]: true, @@ -430,8 +445,8 @@ }; if ( - threadType === threadTypes.COMMUNITY_OPEN_SUBTHREAD || - threadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD + thinThreadType === threadTypes.COMMUNITY_OPEN_SUBTHREAD || + thinThreadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD ) { const memberPermissions = { [threadPermissions.REMOVE_MEMBERS]: true, @@ -445,21 +460,21 @@ } if ( - threadType === threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD || - threadType === threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD + thinThreadType === threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD || + thinThreadType === threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD ) { return { Members: subthreadBasePermissions, }; } - return getRolePermissionBlobsForCommunityRoot(threadType); + return getRolePermissionBlobsForCommunityRoot(thinThreadType); } // ESLint doesn't recognize that invariant always throws // eslint-disable-next-line consistent-return function getUniversalCommunityRootPermissionsBlob( - threadType: ThreadType, + threadType: ThinThreadType, ): ThreadRolePermissionsBlob { const openDescendantKnowOf = OPEN_DESCENDANT + threadPermissions.KNOW_OF; const openDescendantVisible = OPEN_DESCENDANT + threadPermissions.VISIBLE; @@ -496,6 +511,36 @@ invariant(false, 'invalid threadType parameter'); } +function getThickThreadRolePermissionsBlob( + threadType: ThickThreadType, +): ThreadRolePermissionsBlob { + invariant(threadTypeIsThick(threadType), 'ThreadType should be thick'); + const basePermissions = { + [threadPermissions.KNOW_OF]: true, + [threadPermissions.VISIBLE]: true, + [threadPermissions.VOICED]: true, + [threadPermissions.REACT_TO_MESSAGE]: true, + [threadPermissions.EDIT_MESSAGE]: true, + [threadPermissions.EDIT_THREAD_NAME]: true, + [threadPermissions.EDIT_THREAD_COLOR]: true, + [threadPermissions.EDIT_THREAD_DESCRIPTION]: true, + [threadPermissions.EDIT_THREAD_AVATAR]: true, + [threadPermissions.ADD_MEMBERS]: true, + [threadPermissions.LEAVE_THREAD]: true, + }; + if (threadType === threadTypes.THICK_SIDEBAR) { + return { + ...basePermissions, + [threadPermissions.JOIN_THREAD]: true, + }; + } + return { + ...basePermissions, + [threadPermissions.EDIT_ENTRIES]: true, + [threadPermissions.CREATE_SIDEBARS]: true, + }; +} + export { permissionLookup, getAllThreadPermissions, @@ -505,4 +550,5 @@ getThreadPermissionBlobFromUserSurfacedPermissions, getRolePermissionBlobs, getUniversalCommunityRootPermissionsBlob, + getThickThreadRolePermissionsBlob, };