Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32562392
D10313.1767338242.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D10313.1767338242.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
@@ -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';
@@ -50,6 +56,25 @@
: minimallyEncodeMemberInfo(rawMember);
});
+ // 2. Validate and potentially minimally encode `rawRoles`.
+ const rawRoles = JSON.parse(clientDBThreadInfo.roles);
+ const minimallyEncodedRoles: { +[id: string]: MinimallyEncodedRoleInfo } =
+ Object.keys(rawRoles).reduce(
+ (acc: { [string]: MinimallyEncodedRoleInfo }, roleID: string) => {
+ const roleInfo = rawRoles[roleID];
+ invariant(
+ minimallyEncodedRoleInfoValidator.is(roleInfo) ||
+ legacyRoleInfoValidator.is(roleInfo),
+ 'rawRole must be valid [MinimallyEncoded/Legacy]RoleInfo',
+ );
+ acc[roleID] = roleInfo.minimallyEncoded
+ ? roleInfo
+ : minimallyEncodeRoleInfo(roleInfo);
+ return acc;
+ },
+ {},
+ );
+
let rawThreadInfo: MinimallyEncodedRawThreadInfo = {
minimallyEncoded: true,
id: clientDBThreadInfo.id,
@@ -62,7 +87,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
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 2, 7:17 AM (1 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5878656
Default Alt Text
D10313.1767338242.diff (2 KB)
Attached To
Mode
D10313: [lib] Update `convertClientDBThreadInfoToRawThreadInfo` to validate `RoleInfo`s
Attached
Detach File
Event Timeline
Log In to Comment