diff --git a/keyserver/src/creators/role-creator.js b/keyserver/src/creators/role-creator.js --- a/keyserver/src/creators/role-creator.js +++ b/keyserver/src/creators/role-creator.js @@ -15,7 +15,7 @@ type ThreadType, } from 'lib/types/thread-types-enum.js'; import type { - LegacyRoleInfo, + ClientLegacyRoleInfo, RoleModificationRequest, RoleModificationResult, } from 'lib/types/thread-types.js'; @@ -34,8 +34,8 @@ import { updateRole } from '../updaters/thread-updaters.js'; type InitialRoles = { - +default: LegacyRoleInfo, - +creator: LegacyRoleInfo, + +default: ClientLegacyRoleInfo, + +creator: ClientLegacyRoleInfo, }; async function createInitialRolesForNewThread( threadID: string, diff --git a/keyserver/src/fetchers/role-fetchers.js b/keyserver/src/fetchers/role-fetchers.js --- a/keyserver/src/fetchers/role-fetchers.js +++ b/keyserver/src/fetchers/role-fetchers.js @@ -1,11 +1,11 @@ // @flow import { specialRoles } from 'lib/permissions/special-roles.js'; -import type { LegacyRoleInfo } from 'lib/types/thread-types.js'; +import type { ClientLegacyRoleInfo } from 'lib/types/thread-types.js'; import { dbQuery, SQL } from '../database/database.js'; -async function fetchRoles(threadID: string): Promise { +async function fetchRoles(threadID: string): Promise { const query = SQL` SELECT id, name, permissions, special_role = ${specialRoles.DEFAULT_ROLE} AS is_default @@ -14,7 +14,7 @@ `; const [result] = await dbQuery(query); - const roles: Array = []; + const roles: Array = []; for (const row of result) { roles.push({ id: row.id.toString(), 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 @@ -20,7 +20,7 @@ import { legacyMemberInfoValidator, legacyRawThreadInfoValidator, - legacyRoleInfoValidator, + clientLegacyRoleInfoValidator, legacyThreadCurrentUserInfoValidator, } from '../types/thread-types.js'; import type { LegacyRawThreadInfo } from '../types/thread-types.js'; @@ -28,7 +28,7 @@ import { tBool, tID, tShape } from '../utils/validation-utils.js'; const roleInfoValidator: TInterface = tShape({ - ...legacyRoleInfoValidator.meta.props, + ...clientLegacyRoleInfoValidator.meta.props, minimallyEncoded: tBool(true), permissions: t.list(tHexEncodedRolePermission), specialRole: t.maybe(specialRoleValidator), 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 @@ -91,7 +91,7 @@ } from '../types/thread-types-enum.js'; import type { LegacyRawThreadInfo, - LegacyRoleInfo, + ClientLegacyRoleInfo, ServerThreadInfo, ServerMemberInfo, ClientNewThreadRequest, @@ -1047,7 +1047,7 @@ return !!memberInfo.permissions[threadPermissions.CHANGE_ROLE]?.value; } -function roleIsAdminRole(roleInfo: ?LegacyRoleInfo | ?RoleInfo): boolean { +function roleIsAdminRole(roleInfo: ?ClientLegacyRoleInfo | ?RoleInfo): boolean { return !!(roleInfo && !roleInfo.isDefault && roleInfo.name === 'Admins'); } 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 @@ -8,7 +8,7 @@ import type { LegacyMemberInfo, LegacyRawThreadInfo, - LegacyRoleInfo, + ClientLegacyRoleInfo, LegacyThreadCurrentUserInfo, } from './thread-types.js'; import { @@ -21,13 +21,13 @@ import type { ThreadEntity } from '../utils/entity-text.js'; export type RoleInfo = $ReadOnly<{ - ...LegacyRoleInfo, + ...ClientLegacyRoleInfo, +minimallyEncoded: true, +permissions: $ReadOnlyArray, +specialRole?: ?SpecialRole, }>; -const minimallyEncodeRoleInfo = (roleInfo: LegacyRoleInfo): RoleInfo => { +const minimallyEncodeRoleInfo = (roleInfo: ClientLegacyRoleInfo): RoleInfo => { invariant( !('minimallyEncoded' in roleInfo), 'roleInfo is already minimally encoded.', @@ -41,7 +41,7 @@ const decodeMinimallyEncodedRoleInfo = ( minimallyEncodedRoleInfo: RoleInfo, -): LegacyRoleInfo => { +): ClientLegacyRoleInfo => { const { minimallyEncoded, specialRole, ...rest } = minimallyEncodedRoleInfo; return { ...rest, diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -50,14 +50,14 @@ isSender: t.Boolean, }); -export type LegacyRoleInfo = { +export type ClientLegacyRoleInfo = { +id: string, +name: string, +permissions: ThreadRolePermissionsBlob, +isDefault: boolean, }; -export const legacyRoleInfoValidator: TInterface = - tShape({ +export const clientLegacyRoleInfoValidator: TInterface = + tShape({ id: tID, name: t.String, permissions: threadRolePermissionsBlobValidator, @@ -90,7 +90,7 @@ +containingThreadID: ?string, +community: ?string, +members: $ReadOnlyArray, - +roles: { +[id: string]: LegacyRoleInfo }, + +roles: { +[id: string]: ClientLegacyRoleInfo }, +currentUser: LegacyThreadCurrentUserInfo, +sourceMessageID?: string, +repliesCount: number, @@ -112,7 +112,7 @@ containingThreadID: t.maybe(tID), community: t.maybe(tID), members: t.list(legacyMemberInfoValidator), - roles: t.dict(tID, legacyRoleInfoValidator), + roles: t.dict(tID, clientLegacyRoleInfoValidator), currentUser: legacyThreadCurrentUserInfoValidator, sourceMessageID: t.maybe(tID), repliesCount: t.Number, @@ -148,7 +148,7 @@ +community: ?string, +depth: number, +members: $ReadOnlyArray, - +roles: { +[id: string]: LegacyRoleInfo }, + +roles: { +[id: string]: ClientLegacyRoleInfo }, +sourceMessageID?: string, +repliesCount: number, +pinnedCount: number, diff --git a/lib/utils/thread-ops-utils.js b/lib/utils/thread-ops-utils.js --- a/lib/utils/thread-ops-utils.js +++ b/lib/utils/thread-ops-utils.js @@ -23,7 +23,7 @@ type ClientDBThreadInfo, legacyMemberInfoValidator, type LegacyRawThreadInfo, - legacyRoleInfoValidator, + clientLegacyRoleInfoValidator, legacyThreadCurrentUserInfoValidator, } from '../types/thread-types.js'; @@ -66,7 +66,8 @@ ).reduce((acc: { [string]: RoleInfo }, roleID: string) => { const roleInfo = rawRoles[roleID]; invariant( - roleInfoValidator.is(roleInfo) || legacyRoleInfoValidator.is(roleInfo), + roleInfoValidator.is(roleInfo) || + clientLegacyRoleInfoValidator.is(roleInfo), 'rawRole must be valid [MinimallyEncoded/Legacy]RoleInfo', ); acc[roleID] = roleInfo.minimallyEncoded diff --git a/native/redux/edit-thread-permission-migration.js b/native/redux/edit-thread-permission-migration.js --- a/native/redux/edit-thread-permission-migration.js +++ b/native/redux/edit-thread-permission-migration.js @@ -4,7 +4,7 @@ import type { LegacyMemberInfo, LegacyRawThreadInfo, - LegacyRoleInfo, + ClientLegacyRoleInfo, LegacyRawThreadInfos, LegacyThreadCurrentUserInfo, } from 'lib/types/thread-types.js'; @@ -36,9 +36,9 @@ } function addDetailedThreadEditPermissionsToRole( - role: LegacyRoleInfo, + role: ClientLegacyRoleInfo, threadType: number, -): LegacyRoleInfo { +): ClientLegacyRoleInfo { let updatedPermissions = null; if (role.permissions['edit_thread']) { updatedPermissions = { @@ -74,7 +74,7 @@ threadID, ); - const updatedRoles: { [string]: LegacyRoleInfo } = {}; + const updatedRoles: { [string]: ClientLegacyRoleInfo } = {}; for (const roleID in threadInfo.roles) { updatedRoles[roleID] = addDetailedThreadEditPermissionsToRole( threadInfo.roles[roleID], diff --git a/native/redux/manage-pins-permission-migration.js b/native/redux/manage-pins-permission-migration.js --- a/native/redux/manage-pins-permission-migration.js +++ b/native/redux/manage-pins-permission-migration.js @@ -4,7 +4,7 @@ LegacyRawThreadInfo, LegacyMemberInfo, LegacyThreadCurrentUserInfo, - LegacyRoleInfo, + ClientLegacyRoleInfo, LegacyRawThreadInfos, } from 'lib/types/thread-types.js'; @@ -38,8 +38,8 @@ } function addManagePinsThreadPermissionToRole( - role: LegacyRoleInfo, -): LegacyRoleInfo { + role: ClientLegacyRoleInfo, +): ClientLegacyRoleInfo { const isAdminRole = role.name === adminRoleName; let updatedPermissions; @@ -72,7 +72,7 @@ threadID, ); - const updatedRoles: { [string]: LegacyRoleInfo } = {}; + const updatedRoles: { [string]: ClientLegacyRoleInfo } = {}; for (const roleID in threadInfo.roles) { updatedRoles[roleID] = addManagePinsThreadPermissionToRole( threadInfo.roles[roleID], diff --git a/native/redux/remove-select-role-permissions.js b/native/redux/remove-select-role-permissions.js --- a/native/redux/remove-select-role-permissions.js +++ b/native/redux/remove-select-role-permissions.js @@ -3,7 +3,7 @@ import type { LegacyRawThreadInfos, LegacyRawThreadInfo, - LegacyRoleInfo, + ClientLegacyRoleInfo, } from 'lib/types/thread-types.js'; import { permissionsToRemoveInMigration } from 'lib/utils/migration-utils.js'; @@ -22,7 +22,7 @@ const threadInfo = rawThreadInfos[threadID]; const { roles } = threadInfo; - const updatedRoles: { [string]: LegacyRoleInfo } = {}; + const updatedRoles: { [string]: ClientLegacyRoleInfo } = {}; for (const roleID in roles) { const role = roles[roleID]; const { permissions: rolePermissions } = role;