diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js --- a/keyserver/src/push/send.js +++ b/keyserver/src/push/send.js @@ -131,10 +131,16 @@ const rawThreadInfo = rawThreadInfoFromServerThreadInfo( serverThreadInfo, userID, + { minimallyEncodePermissions: true }, ); if (!rawThreadInfo) { return null; } + invariant( + rawThreadInfo.minimallyEncoded, + 'rawThreadInfo from rawThreadInfoFromServerThreadInfo must be ' + + 'minimallyEncoded when minimallyEncodePermissions option is set', + ); return threadInfoFromRawThreadInfo(rawThreadInfo, userID, userInfos); }), _pickBy(threadInfo => threadInfo), diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -58,14 +58,17 @@ type RobotextMessageInfo, } from '../types/message-types.js'; import type { + MinimallyEncodedRoleInfo, MinimallyEncodedThreadCurrentUserInfo, RawThreadInfo, ThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import { decodeMinimallyEncodedRoleInfo, + minimallyEncodeMemberInfo, minimallyEncodeRawThreadInfo, - minimallyEncodeThreadInfo, + minimallyEncodeRoleInfo, + minimallyEncodeThreadCurrentUserInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; import { @@ -75,6 +78,7 @@ threadPermissionPropagationPrefixes, threadPermissions, type ThreadPermissionsInfo, + type ThreadRolePermissionsBlob, type UserSurfacedPermission, } from '../types/thread-permission-types.js'; import { @@ -87,7 +91,6 @@ ChangeThreadSettingsPayload, ClientNewThreadRequest, LegacyRawThreadInfo, - LegacyThreadInfo, MemberInfo, MixedRawThreadInfos, NewThreadResult, @@ -350,7 +353,7 @@ const memberIDs = members.map(member => member.id); const threadID = getPendingThreadID(threadType, memberIDs, sourceMessageID); - const permissions = { + const permissions: ThreadRolePermissionsBlob = { [threadPermissions.KNOW_OF]: true, [threadPermissions.VISIBLE]: true, [threadPermissions.VOICED]: true, @@ -360,14 +363,15 @@ makePermissionsBlob(permissions, null, threadID, threadType), threadID, ); - const role = { + const role: MinimallyEncodedRoleInfo = minimallyEncodeRoleInfo({ id: `${threadID}/role`, name: 'Members', permissions, isDefault: true, - }; + }); - const rawThreadInfo = { + const rawThreadInfo: RawThreadInfo = { + minimallyEncoded: true, id: threadID, type: threadType, name: name ?? null, @@ -377,16 +381,18 @@ parentThreadID: parentThreadInfo?.id ?? null, containingThreadID: getContainingThreadID(parentThreadInfo, threadType), community: getCommunity(parentThreadInfo), - members: members.map(member => ({ - id: member.id, - role: role.id, - permissions: membershipPermissions, - isSender: false, - })), + members: members.map(member => + minimallyEncodeMemberInfo({ + id: member.id, + role: role.id, + permissions: membershipPermissions, + isSender: false, + }), + ), roles: { [role.id]: role, }, - currentUser: { + currentUser: minimallyEncodeThreadCurrentUserInfo({ role: role.id, permissions: membershipPermissions, subscription: { @@ -394,7 +400,7 @@ home: false, }, unread: false, - }, + }), repliesCount: 0, sourceMessageID, pinnedCount: 0, @@ -892,52 +898,31 @@ } function threadInfoFromRawThreadInfo( - rawThreadInfo: LegacyRawThreadInfo | RawThreadInfo, + rawThreadInfo: RawThreadInfo, viewerID: ?string, userInfos: UserInfos, ): ThreadInfo { - let threadInfo: LegacyThreadInfo | ThreadInfo; - if (rawThreadInfo.minimallyEncoded) { - threadInfo = { - minimallyEncoded: true, - id: rawThreadInfo.id, - type: rawThreadInfo.type, - name: rawThreadInfo.name, - uiName: '', - description: rawThreadInfo.description, - color: rawThreadInfo.color, - creationTime: rawThreadInfo.creationTime, - parentThreadID: rawThreadInfo.parentThreadID, - containingThreadID: rawThreadInfo.containingThreadID, - community: rawThreadInfo.community, - members: getRelativeMemberInfos(rawThreadInfo, viewerID, userInfos), - roles: rawThreadInfo.roles, - currentUser: getMinimallyEncodedCurrentUser( - rawThreadInfo, - viewerID, - userInfos, - ), - repliesCount: rawThreadInfo.repliesCount, - }; - } else { - threadInfo = { - id: rawThreadInfo.id, - type: rawThreadInfo.type, - name: rawThreadInfo.name, - uiName: '', - description: rawThreadInfo.description, - color: rawThreadInfo.color, - creationTime: rawThreadInfo.creationTime, - parentThreadID: rawThreadInfo.parentThreadID, - containingThreadID: rawThreadInfo.containingThreadID, - community: rawThreadInfo.community, - members: getRelativeMemberInfos(rawThreadInfo, viewerID, userInfos), - roles: rawThreadInfo.roles, - currentUser: getCurrentUser(rawThreadInfo, viewerID, userInfos), - repliesCount: rawThreadInfo.repliesCount, - }; - threadInfo = minimallyEncodeThreadInfo(threadInfo); - } + let threadInfo: ThreadInfo = { + minimallyEncoded: true, + id: rawThreadInfo.id, + type: rawThreadInfo.type, + name: rawThreadInfo.name, + uiName: '', + description: rawThreadInfo.description, + color: rawThreadInfo.color, + creationTime: rawThreadInfo.creationTime, + parentThreadID: rawThreadInfo.parentThreadID, + containingThreadID: rawThreadInfo.containingThreadID, + community: rawThreadInfo.community, + members: getRelativeMemberInfos(rawThreadInfo, viewerID, userInfos), + roles: rawThreadInfo.roles, + currentUser: getMinimallyEncodedCurrentUser( + rawThreadInfo, + viewerID, + userInfos, + ), + repliesCount: rawThreadInfo.repliesCount, + }; threadInfo = { ...threadInfo,