diff --git a/lib/permissions/minimally-encoded-raw-thread-info-validators.js b/lib/permissions/minimally-encoded-raw-thread-info-validators.js --- a/lib/permissions/minimally-encoded-raw-thread-info-validators.js +++ b/lib/permissions/minimally-encoded-raw-thread-info-validators.js @@ -11,9 +11,8 @@ MemberInfoWithPermissions, ThreadCurrentUserInfo, ThinRawThreadInfo, + ThickRawThreadInfo, RoleInfo, - RoleInfoWithoutSpecialRole, - ThinRawThreadInfoWithoutSpecialRole, MinimallyEncodedThickMemberInfo, MemberInfoSansPermissions, } from '../types/minimally-encoded-thread-permissions-types.js'; @@ -23,6 +22,7 @@ legacyMemberInfoValidator, legacyThinRawThreadInfoValidator, legacyThreadCurrentUserInfoValidator, + legacyThickRawThreadInfoValidator, } from '../types/thread-types.js'; import { tBool, tID, tShape, tUserID } from '../utils/validation-utils.js'; @@ -102,27 +102,21 @@ currentUser: threadCurrentUserInfoValidator, }); -const roleInfoWithoutSpecialRolesValidator: TInterface = - tShape({ - ...roleInfoValidatorBase, - isDefault: t.maybe(t.Boolean), - }); - -const thinRawThreadInfoWithoutSpecialRolesValidator: TInterface = - tShape({ - ...thinRawThreadInfoValidator.meta.props, - roles: t.dict(tID, roleInfoWithoutSpecialRolesValidator), +const thickRawThreadInfoValidator: TInterface = + tShape({ + ...legacyThickRawThreadInfoValidator.meta.props, + minimallyEncoded: tBool(true), + members: t.list(minimallyEncodedThickMemberInfoValidator), + roles: t.dict(tID, roleInfoValidator), + currentUser: threadCurrentUserInfoValidator, }); const mixedThinRawThreadInfoValidator: TUnion< - | LegacyThinRawThreadInfo - | ThinRawThreadInfo - | ThinRawThreadInfoWithoutSpecialRole, -> = t.union([ - legacyThinRawThreadInfoValidator, - thinRawThreadInfoValidator, - thinRawThreadInfoWithoutSpecialRolesValidator, -]); + LegacyThinRawThreadInfo | ThinRawThreadInfo, +> = t.union([legacyThinRawThreadInfoValidator, thinRawThreadInfoValidator]); + +const rawThreadInfoValidator: TUnion = + t.union([thinRawThreadInfoValidator, thickRawThreadInfoValidator]); export { memberInfoWithPermissionsValidator, @@ -133,4 +127,5 @@ threadCurrentUserInfoValidator, thinRawThreadInfoValidator, mixedThinRawThreadInfoValidator, + rawThreadInfoValidator, }; 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 @@ -237,16 +237,6 @@ } }; -export type RoleInfoWithoutSpecialRole = $ReadOnly<{ - ...RoleInfoBase, - +isDefault?: boolean, -}>; - -export type ThinRawThreadInfoWithoutSpecialRole = $ReadOnly<{ - ...ThinRawThreadInfo, - +roles: { +[id: string]: RoleInfoWithoutSpecialRole }, -}>; - export type RelativeMemberInfo = { +id: string, +role: ?string, diff --git a/lib/types/request-types.js b/lib/types/request-types.js --- a/lib/types/request-types.js +++ b/lib/types/request-types.js @@ -26,13 +26,14 @@ entryInconsistencyReportValidatorShape, } from './report-types.js'; import type { LegacyRawThreadInfo } from './thread-types.js'; +import { legacyThreadInfoValidator } from './thread-types.js'; import { type CurrentUserInfo, currentUserInfoValidator, type AccountUserInfo, accountUserInfoValidator, } from './user-types.js'; -import { mixedThinRawThreadInfoValidator } from '../permissions/minimally-encoded-raw-thread-info-validators.js'; +import { rawThreadInfoValidator } from '../permissions/minimally-encoded-raw-thread-info-validators.js'; import { tNumber, tShape, @@ -136,7 +137,7 @@ }>; type StateChanges = Partial<{ - +rawThreadInfos: LegacyRawThreadInfo[] | RawThreadInfo[], + +rawThreadInfos: (LegacyRawThreadInfo | RawThreadInfo)[], +rawEntryInfos: RawEntryInfo[], +currentUserInfo: CurrentUserInfo, +userInfos: AccountUserInfo[], @@ -164,7 +165,9 @@ ), stateChanges: t.maybe( tShape({ - rawThreadInfos: t.maybe(t.list(mixedThinRawThreadInfoValidator)), + rawThreadInfos: t.maybe( + t.list(t.union([legacyThreadInfoValidator, rawThreadInfoValidator])), + ), rawEntryInfos: t.maybe(t.list(rawEntryInfoValidator)), currentUserInfo: t.maybe(currentUserInfoValidator), userInfos: t.maybe(t.list(accountUserInfoValidator)), 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 @@ -1,6 +1,6 @@ // @flow -import t, { type TInterface } from 'tcomb'; +import t, { type TInterface, type TUnion } from 'tcomb'; import { type AvatarDBContent, @@ -35,12 +35,13 @@ type ThinThreadType, type ThickThreadType, thinThreadTypeValidator, + thickThreadTypeValidator, } from './thread-types-enum.js'; import type { ClientUpdateInfo, ServerUpdateInfo } from './update-types.js'; import type { UserInfo, UserInfos } from './user-types.js'; import type { SpecialRole } from '../permissions/special-roles.js'; import { type ThreadEntity } from '../utils/entity-text.js'; -import { tID, tShape, tUserID } from '../utils/validation-utils.js'; +import { tID, tShape, tUserID, tBool } from '../utils/validation-utils.js'; export type LegacyMemberInfo = { +id: string, @@ -200,6 +201,43 @@ pinnedCount: t.maybe(t.Number), }); +export const thickMemberInfoValidator: TInterface = + tShape({ + id: tUserID, + role: t.maybe(tID), + permissions: threadPermissionsInfoValidator, + subscription: threadSubscriptionValidator, + isSender: t.Boolean, + }); + +export const legacyThickRawThreadInfoValidator: TInterface = + tShape({ + thick: tBool(true), + id: tID, + type: thickThreadTypeValidator, + name: t.maybe(t.String), + avatar: t.maybe(clientAvatarValidator), + description: t.maybe(t.String), + color: t.String, + creationTime: t.Number, + parentThreadID: t.maybe(tID), + containingThreadID: t.maybe(tID), + members: t.list(thickMemberInfoValidator), + roles: t.dict(tID, clientLegacyRoleInfoValidator), + currentUser: legacyThreadCurrentUserInfoValidator, + sourceMessageID: t.maybe(tID), + repliesCount: t.Number, + pinnedCount: t.maybe(t.Number), + timestamps: threadTimestampsValidator, + }); + +export const legacyThreadInfoValidator: TUnion< + LegacyThinRawThreadInfo | LegacyThickRawThreadInfo, +> = t.union([ + legacyThinRawThreadInfoValidator, + legacyThickRawThreadInfoValidator, +]); + export type MixedRawThreadInfos = { +[id: string]: LegacyRawThreadInfo | RawThreadInfo, }; diff --git a/lib/types/validators/redux-state-validators.js b/lib/types/validators/redux-state-validators.js --- a/lib/types/validators/redux-state-validators.js +++ b/lib/types/validators/redux-state-validators.js @@ -2,7 +2,7 @@ import t, { type TInterface } from 'tcomb'; -import { mixedThinRawThreadInfoValidator } from '../../permissions/minimally-encoded-raw-thread-info-validators.js'; +import { rawThreadInfoValidator } from '../../permissions/minimally-encoded-raw-thread-info-validators.js'; import { tShape, tID } from '../../utils/validation-utils.js'; import { entryStoreValidator } from '../entry-types.js'; import { inviteLinksStoreValidator } from '../link-types.js'; @@ -22,7 +22,7 @@ export const threadStoreValidator: TInterface = tShape({ - threadInfos: t.dict(tID, mixedThinRawThreadInfoValidator), + threadInfos: t.dict(tID, rawThreadInfoValidator), }); export const initialReduxStateValidator: TInterface =