diff --git a/keyserver/src/fetchers/thread-fetchers.js b/keyserver/src/fetchers/thread-fetchers.js --- a/keyserver/src/fetchers/thread-fetchers.js +++ b/keyserver/src/fetchers/thread-fetchers.js @@ -9,14 +9,17 @@ getContainingThreadID, getCommunity, } from 'lib/shared/thread-utils.js'; -import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; +import { + FUTURE_CODE_VERSION, + hasMinCodeVersion, +} from 'lib/shared/version-utils.js'; import type { AvatarDBContent, ClientAvatar } from 'lib/types/avatar-types.js'; import type { RawMessageInfo, MessageInfo } from 'lib/types/message-types.js'; import { threadTypes, type ThreadType } from 'lib/types/thread-types-enum.js'; import { - type LegacyRawThreadInfos, type ServerThreadInfo, - type LegacyRawThreadInfo, + type RawThreadInfos, + type RawThreadInfo, } from 'lib/types/thread-types.js'; import { ServerError } from 'lib/utils/errors.js'; @@ -245,7 +248,7 @@ } export type FetchThreadInfosResult = { - +threadInfos: LegacyRawThreadInfos, + +threadInfos: RawThreadInfos, }; async function fetchThreadInfos( @@ -277,8 +280,12 @@ const codeVersionBelow283 = !hasMinCodeVersion(viewer.platformDetails, { native: 285, }); + const minimallyEncodedPermissionsSupported = hasMinCodeVersion( + viewer.platformDetails, + { native: FUTURE_CODE_VERSION }, + ); - const threadInfos: { [string]: LegacyRawThreadInfo } = {}; + const threadInfos: { [string]: RawThreadInfo } = {}; for (const threadID in serverResult.threadInfos) { const serverThreadInfo = serverResult.threadInfos[threadID]; const threadInfo = rawThreadInfoFromServerThreadInfo( @@ -289,6 +296,7 @@ excludePinInfo: codeVersionBelow209, filterManageInviteLinksPermission: codeVersionBelow221, filterVoicedInAnnouncementChannelsPermission: codeVersionBelow283, + minimallyEncodePermissions: minimallyEncodedPermissionsSupported, }, ); if (threadInfo) { diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -11,6 +11,7 @@ policies, policyTypeValidator, } from 'lib/facts/policies.js'; +import { rawThreadInfoValidator } from 'lib/permissions/minimally-encoded-thread-permissions-validators.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import type { ResetPasswordRequest, @@ -437,7 +438,7 @@ rawEntryInfos: t.maybe(t.list(rawEntryInfoValidator)), serverTime: t.Number, cookieChange: tShape({ - threadInfos: t.dict(tID, legacyRawThreadInfoValidator), + threadInfos: t.dict(tID, rawThreadInfoValidator), userInfos: t.list(userInfoValidator), }), notAcknowledgedPolicies: t.maybe(t.list(policyTypeValidator)), 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 @@ -65,6 +65,7 @@ } from '../types/minimally-encoded-thread-permissions-types.js'; import { decodeMinimallyEncodedRoleInfo, + minimallyEncodeRawThreadInfo, minimallyEncodeThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; @@ -736,12 +737,13 @@ +excludePinInfo?: boolean, +filterManageInviteLinksPermission?: boolean, +filterVoicedInAnnouncementChannelsPermission?: boolean, + +minimallyEncodePermissions?: boolean, }; function rawThreadInfoFromServerThreadInfo( serverThreadInfo: ServerThreadInfo, viewerID: string, options?: RawThreadInfoOptions, -): ?LegacyRawThreadInfo { +): ?RawThreadInfo { const filterThreadEditAvatarPermission = options?.filterThreadEditAvatarPermission; const excludePinInfo = options?.excludePinInfo; @@ -749,6 +751,7 @@ options?.filterManageInviteLinksPermission; const filterVoicedInAnnouncementChannelsPermission = options?.filterVoicedInAnnouncementChannelsPermission; + const shouldMinimallyEncodePermissions = options?.minimallyEncodePermissions; const filterThreadPermissions = _omitBy( (v, k) => @@ -853,12 +856,14 @@ rawThreadInfo = { ...rawThreadInfo, avatar: serverThreadInfo.avatar }; } if (!excludePinInfo) { - return { + rawThreadInfo = { ...rawThreadInfo, pinnedCount: serverThreadInfo.pinnedCount, }; } - return rawThreadInfo; + return shouldMinimallyEncodePermissions + ? minimallyEncodeRawThreadInfo(rawThreadInfo) + : rawThreadInfo; } function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity {