diff --git a/lib/permissions/minimally-encoded-thread-permissions-validators.js b/lib/permissions/minimally-encoded-thread-permissions-validators.js --- a/lib/permissions/minimally-encoded-thread-permissions-validators.js +++ b/lib/permissions/minimally-encoded-thread-permissions-validators.js @@ -6,6 +6,7 @@ tHexEncodedPermissionsBitmask, tHexEncodedRolePermission, } from './minimally-encoded-thread-permissions.js'; +import { specialRoleValidator } from './special-roles.js'; import { clientAvatarValidator } from '../types/avatar-types.js'; import type { MemberInfo, @@ -30,6 +31,7 @@ ...legacyRoleInfoValidator.meta.props, minimallyEncoded: tBool(true), permissions: t.list(tHexEncodedRolePermission), + specialRole: t.maybe(specialRoleValidator), }); const threadCurrentUserInfoValidator: TInterface = diff --git a/lib/permissions/special-roles.js b/lib/permissions/special-roles.js --- a/lib/permissions/special-roles.js +++ b/lib/permissions/special-roles.js @@ -1,10 +1,20 @@ // @flow +import type { TRefinement } from 'tcomb'; + +import { values } from '../utils/objects.js'; +import { tNumEnum } from '../utils/validation-utils.js'; + export const specialRoles = Object.freeze({ DEFAULT_ROLE: 1, ADMIN_ROLE: 2, }); +export type SpecialRole = $Values; +export const specialRoleValidator: TRefinement = tNumEnum( + values(specialRoles), +); + export const defaultSpecialRoles = Object.freeze({ Members: specialRoles.DEFAULT_ROLE, Admins: specialRoles.ADMIN_ROLE, diff --git a/lib/types/minimally-encoded-thread-permissions-types.js b/lib/types/minimally-encoded-thread-permissions-types.js --- a/lib/types/minimally-encoded-thread-permissions-types.js +++ b/lib/types/minimally-encoded-thread-permissions-types.js @@ -17,12 +17,14 @@ threadPermissionsFromBitmaskHex, threadRolePermissionsBlobToBitmaskArray, } from '../permissions/minimally-encoded-thread-permissions.js'; +import type { SpecialRole } from '../permissions/special-roles.js'; import type { ThreadEntity } from '../utils/entity-text.js'; export type RoleInfo = $ReadOnly<{ ...LegacyRoleInfo, +minimallyEncoded: true, +permissions: $ReadOnlyArray, + +specialRole?: ?SpecialRole, }>; const minimallyEncodeRoleInfo = (roleInfo: LegacyRoleInfo): RoleInfo => { @@ -40,7 +42,7 @@ const decodeMinimallyEncodedRoleInfo = ( minimallyEncodedRoleInfo: RoleInfo, ): LegacyRoleInfo => { - const { minimallyEncoded, ...rest } = minimallyEncodedRoleInfo; + const { minimallyEncoded, specialRole, ...rest } = minimallyEncodedRoleInfo; return { ...rest, permissions: decodeThreadRolePermissionsBitmaskArray(