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 { - RoleInfo, + LegacyRoleInfo, RoleModificationRequest, RoleModificationResult, } from 'lib/types/thread-types.js'; @@ -34,8 +34,8 @@ import { updateRole } from '../updaters/thread-updaters.js'; type InitialRoles = { - +default: RoleInfo, - +creator: RoleInfo, + +default: LegacyRoleInfo, + +creator: LegacyRoleInfo, }; 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 { RoleInfo } from 'lib/types/thread-types.js'; +import type { LegacyRoleInfo } 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 @@ -17,7 +17,7 @@ import { memberInfoValidator, rawThreadInfoValidator, - roleInfoValidator, + legacyRoleInfoValidator, threadCurrentUserInfoValidator, threadInfoValidator, } from '../types/thread-types.js'; @@ -25,7 +25,7 @@ const minimallyEncodedRoleInfoValidator: TInterface = tShape({ - ...roleInfoValidator.meta.props, + ...legacyRoleInfoValidator.meta.props, minimallyEncoded: tBool(true), permissions: t.list(tHexEncodedRolePermission), }); 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 @@ -89,7 +89,7 @@ type ServerThreadInfo, type RelativeMemberInfo, type ThreadCurrentUserInfo, - type RoleInfo, + type LegacyRoleInfo, type ServerMemberInfo, type ClientNewThreadRequest, type NewThreadResult, @@ -1171,7 +1171,7 @@ } function roleIsAdminRole( - roleInfo: ?RoleInfo | ?MinimallyEncodedRoleInfo, + roleInfo: ?LegacyRoleInfo | ?MinimallyEncodedRoleInfo, ): 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 @@ -6,7 +6,7 @@ MemberInfo, RawThreadInfo, RelativeMemberInfo, - RoleInfo, + LegacyRoleInfo, ThreadCurrentUserInfo, ThreadInfo, } from './thread-types.js'; @@ -18,13 +18,13 @@ } from '../permissions/minimally-encoded-thread-permissions.js'; export type MinimallyEncodedRoleInfo = $ReadOnly<{ - ...RoleInfo, + ...LegacyRoleInfo, +minimallyEncoded: true, +permissions: $ReadOnlyArray, }>; const minimallyEncodeRoleInfo = ( - roleInfo: RoleInfo, + roleInfo: LegacyRoleInfo, ): MinimallyEncodedRoleInfo => ({ ...roleInfo, minimallyEncoded: true, @@ -33,7 +33,7 @@ const decodeMinimallyEncodedRoleInfo = ( minimallyEncodedRoleInfo: MinimallyEncodedRoleInfo, -): RoleInfo => { +): LegacyRoleInfo => { const { minimallyEncoded, ...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 @@ -60,18 +60,19 @@ isViewer: t.Boolean, }); -export type RoleInfo = { +export type LegacyRoleInfo = { +id: string, +name: string, +permissions: ThreadRolePermissionsBlob, +isDefault: boolean, }; -export const roleInfoValidator: TInterface = tShape({ - id: tID, - name: t.String, - permissions: threadRolePermissionsBlobValidator, - isDefault: t.Boolean, -}); +export const legacyRoleInfoValidator: TInterface = + tShape({ + id: tID, + name: t.String, + permissions: threadRolePermissionsBlobValidator, + isDefault: t.Boolean, + }); export type ThreadCurrentUserInfo = { +role: ?string, @@ -99,7 +100,7 @@ +containingThreadID: ?string, +community: ?string, +members: $ReadOnlyArray, - +roles: { +[id: string]: RoleInfo }, + +roles: { +[id: string]: LegacyRoleInfo }, +currentUser: ThreadCurrentUserInfo, +sourceMessageID?: string, +repliesCount: number, @@ -121,7 +122,7 @@ containingThreadID: t.maybe(tID), community: t.maybe(tID), members: t.list(memberInfoValidator), - roles: t.dict(tID, roleInfoValidator), + roles: t.dict(tID, legacyRoleInfoValidator), currentUser: threadCurrentUserInfoValidator, sourceMessageID: t.maybe(tID), repliesCount: t.Number, @@ -141,7 +142,7 @@ +containingThreadID: ?string, +community: ?string, +members: $ReadOnlyArray, - +roles: { +[id: string]: RoleInfo }, + +roles: { +[id: string]: LegacyRoleInfo }, +currentUser: ThreadCurrentUserInfo, +sourceMessageID?: string, +repliesCount: number, @@ -160,7 +161,7 @@ containingThreadID: t.maybe(tID), community: t.maybe(tID), members: t.list(relativeMemberInfoValidator), - roles: t.dict(tID, roleInfoValidator), + roles: t.dict(tID, legacyRoleInfoValidator), currentUser: threadCurrentUserInfoValidator, sourceMessageID: t.maybe(tID), repliesCount: t.Number, @@ -180,7 +181,7 @@ +containingThreadID: ?string, +community: ?string, +members: $ReadOnlyArray, - +roles: { +[id: string]: RoleInfo }, + +roles: { +[id: string]: LegacyRoleInfo }, +currentUser: ThreadCurrentUserInfo, +sourceMessageID?: string, +repliesCount: number, @@ -209,7 +210,7 @@ +community: ?string, +depth: number, +members: $ReadOnlyArray, - +roles: { +[id: string]: RoleInfo }, + +roles: { +[id: string]: LegacyRoleInfo }, +sourceMessageID?: string, +repliesCount: number, +pinnedCount: number, diff --git a/lib/utils/role-utils.js b/lib/utils/role-utils.js --- a/lib/utils/role-utils.js +++ b/lib/utils/role-utils.js @@ -17,7 +17,7 @@ import type { ThreadInfo, RelativeMemberInfo, - RoleInfo, + LegacyRoleInfo, } from '../types/thread-types'; import { threadTypes } from '../types/thread-types-enum.js'; @@ -65,7 +65,7 @@ memberInfos: $ReadOnlyArray< RelativeMemberInfo | MinimallyEncodedRelativeMemberInfo, >, -): $ReadOnlyMap { +): $ReadOnlyMap { // Our in-code system has chat-specific roles, while the // user-surfaced system has roles only for communities. We retrieve roles // from the top-level community thread for accuracy, with a rare fallback @@ -80,7 +80,10 @@ community ? threadInfoSelector(state)[community] : null, ); const topMostThreadInfo = communityThreadInfo || threadInfo; - const roleMap = new Map(); + const roleMap = new Map< + string, + ?LegacyRoleInfo | ?MinimallyEncodedRoleInfo, + >(); if (topMostThreadInfo.type === threadTypes.GENESIS) { memberInfos.forEach(memberInfo => 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 @@ -5,7 +5,7 @@ MemberInfo, ThreadCurrentUserInfo, RawThreadInfo, - RoleInfo, + LegacyRoleInfo, RawThreadInfos, } from 'lib/types/thread-types.js'; @@ -36,9 +36,9 @@ } function addDetailedThreadEditPermissionsToRole( - role: RoleInfo, + role: LegacyRoleInfo, threadType: number, -): RoleInfo { +): LegacyRoleInfo { let updatedPermissions = null; if (role.permissions['edit_thread']) { updatedPermissions = { @@ -74,7 +74,7 @@ threadID, ); - const updatedRoles: { [string]: RoleInfo } = {}; + const updatedRoles: { [string]: LegacyRoleInfo } = {}; 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 @@ RawThreadInfo, MemberInfo, ThreadCurrentUserInfo, - RoleInfo, + LegacyRoleInfo, RawThreadInfos, } from 'lib/types/thread-types.js'; @@ -37,7 +37,9 @@ : member; } -function addManagePinsThreadPermissionToRole(role: RoleInfo): RoleInfo { +function addManagePinsThreadPermissionToRole( + role: LegacyRoleInfo, +): LegacyRoleInfo { const isAdminRole = role.name === adminRoleName; let updatedPermissions; @@ -70,7 +72,7 @@ threadID, ); - const updatedRoles: { [string]: RoleInfo } = {}; + const updatedRoles: { [string]: LegacyRoleInfo } = {}; 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 { RawThreadInfos, RawThreadInfo, - RoleInfo, + LegacyRoleInfo, } 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]: RoleInfo } = {}; + const updatedRoles: { [string]: LegacyRoleInfo } = {}; for (const roleID in roles) { const role = roles[roleID]; const { permissions: rolePermissions } = role;