Page MenuHomePhabricator

D10298.id34582.diff
No OneTemporary

D10298.id34582.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
@@ -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

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)

Event Timeline