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 @@ -9,7 +9,7 @@ import { clientAvatarValidator } from '../types/avatar-types.js'; import type { MemberInfo, - MinimallyEncodedThreadCurrentUserInfo, + ThreadCurrentUserInfo, RawThreadInfo, RelativeMemberInfo, RoleInfo, @@ -33,8 +33,8 @@ permissions: t.list(tHexEncodedRolePermission), }); -const minimallyEncodedThreadCurrentUserInfoValidator: TInterface = - tShape({ +const threadCurrentUserInfoValidator: TInterface = + tShape({ ...legacyThreadCurrentUserInfoValidator.meta.props, minimallyEncoded: tBool(true), permissions: tHexEncodedPermissionsBitmask, @@ -69,7 +69,7 @@ community: t.maybe(tID), members: t.list(minimallyEncodedRelativeMemberInfoValidator), roles: t.dict(tID, minimallyEncodedRoleInfoValidator), - currentUser: minimallyEncodedThreadCurrentUserInfoValidator, + currentUser: threadCurrentUserInfoValidator, sourceMessageID: t.maybe(tID), repliesCount: t.Number, pinnedCount: t.maybe(t.Number), @@ -81,7 +81,7 @@ minimallyEncoded: tBool(true), members: t.list(MemberInfoValidator), roles: t.dict(tID, minimallyEncodedRoleInfoValidator), - currentUser: minimallyEncodedThreadCurrentUserInfoValidator, + currentUser: threadCurrentUserInfoValidator, }); export const rawThreadInfoValidator: TUnion< @@ -93,7 +93,7 @@ export { minimallyEncodedRoleInfoValidator, - minimallyEncodedThreadCurrentUserInfoValidator, + threadCurrentUserInfoValidator, MemberInfoValidator, minimallyEncodedRelativeMemberInfoValidator, minimallyEncodedThreadInfoValidator, diff --git a/lib/permissions/minimally-encoded-thread-permissions.test.js b/lib/permissions/minimally-encoded-thread-permissions.test.js --- a/lib/permissions/minimally-encoded-thread-permissions.test.js +++ b/lib/permissions/minimally-encoded-thread-permissions.test.js @@ -9,7 +9,7 @@ MemberInfoValidator, minimallyEncodedRawThreadInfoValidator, minimallyEncodedRoleInfoValidator, - minimallyEncodedThreadCurrentUserInfoValidator, + threadCurrentUserInfoValidator, } from './minimally-encoded-thread-permissions-validators.js'; import { decodeRolePermissionBitmask, @@ -401,14 +401,14 @@ describe('minimallyEncodedThreadCurrentUserInfoValidator', () => { it('should validate correctly formed MinimallyEncodedThreadCurrentUserInfo', () => { expect( - minimallyEncodedThreadCurrentUserInfoValidator.is({ + threadCurrentUserInfoValidator.is({ minimallyEncoded: true, permissions: '100', subscription: { home: true, pushNotifs: true }, }), ).toBe(true); expect( - minimallyEncodedThreadCurrentUserInfoValidator.is({ + threadCurrentUserInfoValidator.is({ minimallyEncoded: true, permissions: 'ABCDEFABCDEFABCD', subscription: { home: true, pushNotifs: true }, @@ -418,7 +418,7 @@ it('should NOT validate malformed MinimallyEncodedThreadCurrentUserInfo', () => { expect( - minimallyEncodedThreadCurrentUserInfoValidator.is({ + threadCurrentUserInfoValidator.is({ minimallyEncoded: true, permissions: 'INVALID', subscription: { home: true, pushNotifs: true }, @@ -426,7 +426,7 @@ ).toBe(false); expect( - minimallyEncodedThreadCurrentUserInfoValidator.is({ + threadCurrentUserInfoValidator.is({ minimallyEncoded: true, permissions: 'ABCDEF hello ABCDEFABCD', subscription: { home: true, pushNotifs: true }, @@ -434,7 +434,7 @@ ).toBe(false); expect( - minimallyEncodedThreadCurrentUserInfoValidator.is({ + threadCurrentUserInfoValidator.is({ minimallyEncoded: true, permissions: 100, subscription: { home: true, pushNotifs: true }, 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 @@ -59,7 +59,7 @@ } from '../types/message-types.js'; import type { MemberInfo, - MinimallyEncodedThreadCurrentUserInfo, + ThreadCurrentUserInfo, RawThreadInfo, RelativeMemberInfo, RoleInfo, @@ -954,7 +954,7 @@ threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, -): MinimallyEncodedThreadCurrentUserInfo { +): ThreadCurrentUserInfo { if (!threadFrozenDueToBlock(threadInfo, viewerID, userInfos)) { return threadInfo.currentUser; } 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 @@ -49,7 +49,7 @@ }; }; -export type MinimallyEncodedThreadCurrentUserInfo = $ReadOnly<{ +export type ThreadCurrentUserInfo = $ReadOnly<{ ...LegacyThreadCurrentUserInfo, +minimallyEncoded: true, +permissions: string, @@ -57,7 +57,7 @@ const minimallyEncodeThreadCurrentUserInfo = ( threadCurrentUserInfo: LegacyThreadCurrentUserInfo, -): MinimallyEncodedThreadCurrentUserInfo => { +): ThreadCurrentUserInfo => { invariant( !('minimallyEncoded' in threadCurrentUserInfo), 'threadCurrentUserInfo is already minimally encoded.', @@ -70,7 +70,7 @@ }; const decodeMinimallyEncodedThreadCurrentUserInfo = ( - minimallyEncodedThreadCurrentUserInfo: MinimallyEncodedThreadCurrentUserInfo, + minimallyEncodedThreadCurrentUserInfo: ThreadCurrentUserInfo, ): LegacyThreadCurrentUserInfo => { const { minimallyEncoded, ...rest } = minimallyEncodedThreadCurrentUserInfo; return { @@ -124,7 +124,7 @@ +minimallyEncoded: true, +members: $ReadOnlyArray, +roles: { +[id: string]: RoleInfo }, - +currentUser: MinimallyEncodedThreadCurrentUserInfo, + +currentUser: ThreadCurrentUserInfo, }>; const minimallyEncodeRawThreadInfo = ( @@ -172,7 +172,7 @@ +community: ?string, +members: $ReadOnlyArray, +roles: { +[id: string]: RoleInfo }, - +currentUser: MinimallyEncodedThreadCurrentUserInfo, + +currentUser: ThreadCurrentUserInfo, +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 @@ -5,7 +5,7 @@ import { MemberInfoValidator, minimallyEncodedRoleInfoValidator, - minimallyEncodedThreadCurrentUserInfoValidator, + threadCurrentUserInfoValidator, } from '../permissions/minimally-encoded-thread-permissions-validators.js'; import type { MemberInfo, @@ -79,7 +79,7 @@ // 3. Validate and potentially minimally encode `rawCurrentUser`. const rawCurrentUser = JSON.parse(clientDBThreadInfo.currentUser); invariant( - minimallyEncodedThreadCurrentUserInfoValidator.is(rawCurrentUser) || + threadCurrentUserInfoValidator.is(rawCurrentUser) || legacyThreadCurrentUserInfoValidator.is(rawCurrentUser), 'rawCurrentUser must be valid [MinimallyEncoded]ThreadCurrentUserInfo', );