Page MenuHomePhabricator

D10314.diff
No OneTemporary

D10314.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(
@@ -75,6 +78,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,
@@ -88,7 +102,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
Wed, Nov 6, 8:47 PM (19 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2432206
Default Alt Text
D10314.diff (1 KB)

Event Timeline