Page MenuHomePhabricator

D10313.id34537.diff
No OneTemporary

D10313.id34537.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
@@ -2,20 +2,26 @@
import invariant from 'invariant';
-import { minimallyEncodedMemberInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js';
+import {
+ minimallyEncodedMemberInfoValidator,
+ minimallyEncodedRoleInfoValidator,
+} from '../permissions/minimally-encoded-thread-permissions-validators.js';
import type {
MinimallyEncodedMemberInfo,
MinimallyEncodedRawThreadInfo,
+ MinimallyEncodedRoleInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import {
decodeMinimallyEncodedRawThreadInfo,
minimallyEncodeMemberInfo,
+ minimallyEncodeRoleInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import { assertThreadType } from '../types/thread-types-enum.js';
import {
type ClientDBThreadInfo,
legacyMemberInfoValidator,
type LegacyRawThreadInfo,
+ legacyRoleInfoValidator,
type RawThreadInfo,
} from '../types/thread-types.js';
@@ -52,6 +58,27 @@
: minimallyEncodeMemberInfo(rawMember),
);
+ // 2. Validate and potentially minimally encode `rawRoles`.
+ const rawRoles = JSON.parse(clientDBThreadInfo.roles);
+ Object.keys(rawRoles).forEach(idx =>
+ invariant(
+ minimallyEncodedRoleInfoValidator.is(rawRoles[idx]) ||
+ legacyRoleInfoValidator.is(rawRoles[idx]),
+ 'rawRole must be correctly formed [MinimallyEncoded/Legacy]RoleInfo',
+ ),
+ );
+ const minimallyEncodedRoles: { +[id: string]: MinimallyEncodedRoleInfo } =
+ Object.keys(rawRoles).reduce(
+ (acc: { [string]: MinimallyEncodedRoleInfo }, roleID: string) => {
+ const roleInfo = rawRoles[roleID];
+ acc[roleID] = roleInfo.minimallyEncoded
+ ? roleInfo
+ : minimallyEncodeRoleInfo(roleInfo);
+ return acc;
+ },
+ {},
+ );
+
let rawThreadInfo: MinimallyEncodedRawThreadInfo = {
minimallyEncoded: true,
id: clientDBThreadInfo.id,
@@ -64,7 +91,7 @@
containingThreadID: clientDBThreadInfo.containingThreadID,
community: clientDBThreadInfo.community,
members: minimallyEncodedMembers,
- roles: JSON.parse(clientDBThreadInfo.roles),
+ roles: minimallyEncodedRoles,
currentUser: JSON.parse(clientDBThreadInfo.currentUser),
repliesCount: clientDBThreadInfo.repliesCount,
pinnedCount: clientDBThreadInfo.pinnedCount,

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 6, 9:33 PM (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2432613
Default Alt Text
D10313.id34537.diff (2 KB)

Event Timeline