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,34 @@ pinnedCount: serverThreadInfo.pinnedCount, }; } - return shouldMinimallyEncodePermissions - ? minimallyEncodeRawThreadInfo(rawThreadInfo) - : rawThreadInfo; + + if (!shouldMinimallyEncodePermissions) { + return rawThreadInfo; + } else if (!shouldIncludeSpecialRoleFieldInRoles) { + return minimallyEncodeRawThreadInfo(rawThreadInfo); + } + + const rawThreadInfoWithoutSpecialRoles = + minimallyEncodeRawThreadInfo(rawThreadInfo); + + const rolesWithSpecialRoleField = Object.fromEntries( + Object.entries(rawThreadInfoWithoutSpecialRoles.roles).map( + ([key, role]) => [ + key, + { + ...role, + specialRole: rolesWithFilteredThreadPermissions[key]?.specialRole, + }, + ], + ), + ); + + const rawThreadInfoWithSpecialRolesPatchedIn = { + ...rawThreadInfoWithoutSpecialRoles, + roles: rolesWithSpecialRoleField, + }; + + return rawThreadInfoWithSpecialRolesPatchedIn; } function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity {