Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3159210
D10298.id34580.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10298.id34580.diff
View Options
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
@@ -1,10 +1,20 @@
// @flow
-import type { MinimallyEncodedRawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
-import { decodeMinimallyEncodedRawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
+import invariant from 'invariant';
+
+import { minimallyEncodedMemberInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js';
+import type {
+ MinimallyEncodedMemberInfo,
+ MinimallyEncodedRawThreadInfo,
+} from '../types/minimally-encoded-thread-permissions-types.js';
+import {
+ decodeMinimallyEncodedRawThreadInfo,
+ minimallyEncodeMemberInfo,
+} from '../types/minimally-encoded-thread-permissions-types.js';
import { assertThreadType } from '../types/thread-types-enum.js';
import {
type ClientDBThreadInfo,
+ legacyMemberInfoValidator,
type LegacyRawThreadInfo,
type RawThreadInfo,
} from '../types/thread-types.js';
@@ -26,6 +36,20 @@
function convertClientDBThreadInfoToRawThreadInfo(
clientDBThreadInfo: ClientDBThreadInfo,
): MinimallyEncodedRawThreadInfo {
+ // 1. Validate and potentially minimally encode `rawMembers`.
+ const rawMembers = JSON.parse(clientDBThreadInfo.members);
+ const minimallyEncodedMembers: $ReadOnlyArray<MinimallyEncodedMemberInfo> =
+ rawMembers.map(rawMember => {
+ invariant(
+ minimallyEncodedMemberInfoValidator.is(rawMember) ||
+ legacyMemberInfoValidator.is(rawMember),
+ 'rawMember must be correctly formed [MinimallyEncoded/Legacy]MemberInfo',
+ );
+ return rawMember.minimallyEncoded
+ ? rawMember
+ : minimallyEncodeMemberInfo(rawMember);
+ });
+
let rawThreadInfo: MinimallyEncodedRawThreadInfo = {
minimallyEncoded: true,
id: clientDBThreadInfo.id,
@@ -37,7 +61,7 @@
parentThreadID: clientDBThreadInfo.parentThreadID,
containingThreadID: clientDBThreadInfo.containingThreadID,
community: clientDBThreadInfo.community,
- members: JSON.parse(clientDBThreadInfo.members),
+ members: minimallyEncodedMembers,
roles: JSON.parse(clientDBThreadInfo.roles),
currentUser: JSON.parse(clientDBThreadInfo.currentUser),
repliesCount: clientDBThreadInfo.repliesCount,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 6, 10:25 PM (21 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2433311
Default Alt Text
D10298.id34580.diff (2 KB)
Attached To
Mode
D10298: [lib] Update `convertClientDBThreadInfoToRawThreadInfo` to validate `MemberInfo`s
Attached
Detach File
Event Timeline
Log In to Comment