Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3352414
D10298.id34582.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.id34582.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 valid [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
Sun, Nov 24, 5:48 AM (20 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573660
Default Alt Text
D10298.id34582.diff (2 KB)
Attached To
Mode
D10298: [lib] Update `convertClientDBThreadInfoToRawThreadInfo` to validate `MemberInfo`s
Attached
Detach File
Event Timeline
Log In to Comment