Page MenuHomePhabricator

D9846.diff
No OneTemporary

D9846.diff

diff --git a/lib/types/minimally-encoded-thread-permissions-types.js b/lib/types/minimally-encoded-thread-permissions-types.js
--- a/lib/types/minimally-encoded-thread-permissions-types.js
+++ b/lib/types/minimally-encoded-thread-permissions-types.js
@@ -9,6 +9,7 @@
rawThreadInfoValidator,
roleInfoValidator,
threadCurrentUserInfoValidator,
+ threadInfoValidator,
} from './thread-types.js';
import type {
MemberInfo,
@@ -16,6 +17,7 @@
RelativeMemberInfo,
RoleInfo,
ThreadCurrentUserInfo,
+ ThreadInfo,
} from './thread-types.js';
import {
decodeThreadRolePermissionsBitmaskArray,
@@ -202,6 +204,49 @@
};
};
+export type MinimallyEncodedThreadInfo = $ReadOnly<{
+ ...ThreadInfo,
+ +minimallyEncoded: true,
+ +members: $ReadOnlyArray<MinimallyEncodedRelativeMemberInfo>,
+ +roles: { +[id: string]: MinimallyEncodedRoleInfo },
+ +currentUser: MinimallyEncodedThreadCurrentUserInfo,
+}>;
+
+const minimallyEncodedThreadInfoValidator: TInterface<MinimallyEncodedThreadInfo> =
+ tShape<MinimallyEncodedThreadInfo>({
+ ...threadInfoValidator.meta.props,
+ minimallyEncoded: tBool(true),
+ members: t.list(minimallyEncodedRelativeMemberInfoValidator),
+ roles: t.dict(tID, minimallyEncodedRoleInfoValidator),
+ currentUser: minimallyEncodedThreadCurrentUserInfoValidator,
+ });
+
+const minimallyEncodeThreadInfo = (
+ threadInfo: ThreadInfo,
+): MinimallyEncodedThreadInfo => {
+ const { members, roles, currentUser, ...rest } = threadInfo;
+ return {
+ ...rest,
+ minimallyEncoded: true,
+ members: members.map(minimallyEncodeRelativeMemberInfo),
+ roles: _mapValues(minimallyEncodeRoleInfo)(roles),
+ currentUser: minimallyEncodeThreadCurrentUserInfo(currentUser),
+ };
+};
+
+const decodeMinimallyEncodedThreadInfo = (
+ minimallyEncodedThreadInfo: MinimallyEncodedThreadInfo,
+): ThreadInfo => {
+ const { minimallyEncoded, members, roles, currentUser, ...rest } =
+ minimallyEncodedThreadInfo;
+ return {
+ ...rest,
+ members: members.map(decodeMinimallyEncodedRelativeMemberInfo),
+ roles: _mapValues(decodeMinimallyEncodedRoleInfo)(roles),
+ currentUser: decodeMinimallyEncodedThreadCurrentUserInfo(currentUser),
+ };
+};
+
export {
minimallyEncodedRoleInfoValidator,
minimallyEncodeRoleInfo,
@@ -218,4 +263,7 @@
minimallyEncodedRelativeMemberInfoValidator,
minimallyEncodeRelativeMemberInfo,
decodeMinimallyEncodedRelativeMemberInfo,
+ minimallyEncodedThreadInfoValidator,
+ minimallyEncodeThreadInfo,
+ decodeMinimallyEncodedThreadInfo,
};

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 7:56 PM (20 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2495244
Default Alt Text
D9846.diff (2 KB)

Event Timeline