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 @@ -764,6 +764,8 @@ const filterVoicedInAnnouncementChannelsPermission = options?.filterVoicedInAnnouncementChannelsPermission; const shouldMinimallyEncodePermissions = options?.minimallyEncodePermissions; + const shouldIncludeSpecialRoleFieldInRoles = + options?.includeSpecialRoleFieldInRoles; const filterThreadPermissions = _omitBy( (v, k) => @@ -878,9 +880,23 @@ pinnedCount: serverThreadInfo.pinnedCount, }; } - return shouldMinimallyEncodePermissions - ? minimallyEncodeRawThreadInfo(rawThreadInfo) - : rawThreadInfo; + + if (!shouldMinimallyEncodePermissions) { + return rawThreadInfo; + } else if (!shouldIncludeSpecialRoleFieldInRoles) { + return minimallyEncodeRawThreadInfo(rawThreadInfo); + } + + const minimallyEncodedRolesWithSpecialRoles = _mapValues(role => + minimallyEncodeRoleInfo(role), + )(rolesWithFilteredThreadPermissions); + + const rawThreadInfoWithSpecialRolesPatchedIn = { + ...minimallyEncodeRawThreadInfo(rawThreadInfo), + roles: minimallyEncodedRolesWithSpecialRoles, + }; + + return rawThreadInfoWithSpecialRolesPatchedIn; } function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity {