Page MenuHomePhabricator

D10314.id34549.diff
No OneTemporary

D10314.id34549.diff

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,6 +5,7 @@
import {
minimallyEncodedMemberInfoValidator,
minimallyEncodedRoleInfoValidator,
+ minimallyEncodedThreadCurrentUserInfoValidator,
} from '../permissions/minimally-encoded-thread-permissions-validators.js';
import type {
MinimallyEncodedMemberInfo,
@@ -15,6 +16,7 @@
decodeMinimallyEncodedRawThreadInfo,
minimallyEncodeMemberInfo,
minimallyEncodeRoleInfo,
+ minimallyEncodeThreadCurrentUserInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import { assertThreadType } from '../types/thread-types-enum.js';
import {
@@ -23,6 +25,7 @@
type LegacyRawThreadInfo,
legacyRoleInfoValidator,
type RawThreadInfo,
+ threadCurrentUserInfoValidator,
} from '../types/thread-types.js';
function convertRawThreadInfoToClientDBThreadInfo(
@@ -48,7 +51,7 @@
invariant(
minimallyEncodedMemberInfoValidator.is(rawMember) ||
legacyMemberInfoValidator.is(rawMember),
- 'rawMember must be correctly formed [MinimallyEncoded/Legacy]MemberInfo',
+ 'rawMember must be valid [MinimallyEncoded/Legacy]MemberInfo',
),
);
const minimallyEncodedMembers: $ReadOnlyArray<MinimallyEncodedMemberInfo> =
@@ -64,7 +67,7 @@
invariant(
minimallyEncodedRoleInfoValidator.is(rawRoles[idx]) ||
legacyRoleInfoValidator.is(rawRoles[idx]),
- 'rawRole must be correctly formed [MinimallyEncoded/Legacy]RoleInfo',
+ 'rawRole must be valid [MinimallyEncoded/Legacy]RoleInfo',
),
);
const minimallyEncodedRoles: { +[id: string]: MinimallyEncodedRoleInfo } =
@@ -79,6 +82,17 @@
{},
);
+ // 3. Validate and potentially minimally encode `rawCurrentUser`.
+ const rawCurrentUser = JSON.parse(clientDBThreadInfo.currentUser);
+ invariant(
+ minimallyEncodedThreadCurrentUserInfoValidator.is(rawCurrentUser) ||
+ threadCurrentUserInfoValidator.is(rawCurrentUser),
+ 'rawCurrentUser must be valid [MinimallyEncoded]ThreadCurrentUserInfo',
+ );
+ const minimallyEncodedCurrentUser = rawCurrentUser.minimallyEncoded
+ ? rawCurrentUser
+ : minimallyEncodeThreadCurrentUserInfo(rawCurrentUser);
+
let rawThreadInfo: MinimallyEncodedRawThreadInfo = {
minimallyEncoded: true,
id: clientDBThreadInfo.id,
@@ -92,7 +106,7 @@
community: clientDBThreadInfo.community,
members: minimallyEncodedMembers,
roles: minimallyEncodedRoles,
- currentUser: JSON.parse(clientDBThreadInfo.currentUser),
+ currentUser: minimallyEncodedCurrentUser,
repliesCount: clientDBThreadInfo.repliesCount,
pinnedCount: clientDBThreadInfo.pinnedCount,
};

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 6:55 PM (11 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2708176
Default Alt Text
D10314.id34549.diff (2 KB)

Event Timeline