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 @@ -64,8 +64,9 @@ } from '../types/minimally-encoded-thread-permissions-types.js'; import { decodeMinimallyEncodedRoleInfo, + minimallyEncodeMemberInfo, minimallyEncodeRawThreadInfo, - minimallyEncodeThreadInfo, + minimallyEncodeThreadCurrentUserInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; import { @@ -87,7 +88,6 @@ ChangeThreadSettingsPayload, ClientNewThreadRequest, LegacyRawThreadInfo, - LegacyThreadInfo, MemberInfo, MixedRawThreadInfos, NewThreadResult, @@ -367,7 +367,8 @@ isDefault: true, }; - const rawThreadInfo = { + const rawThreadInfo: RawThreadInfo = { + minimallyEncoded: true, id: threadID, type: threadType, name: name ?? null, @@ -377,16 +378,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 +397,7 @@ home: false, }, unread: false, - }, + }), repliesCount: 0, sourceMessageID, pinnedCount: 0, @@ -892,52 +895,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,