Page MenuHomePhabricator

D10314.id34584.diff
No OneTemporary

D10314.id34584.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
Thu, Dec 26, 6:38 PM (11 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707980
Default Alt Text
D10314.id34584.diff (1 KB)

Event Timeline