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 @@ -119,6 +119,7 @@ type ThreadEntity, type UserEntity, } from '../utils/entity-text.js'; +import { entries } from '../utils/objects.js'; import { useDispatchActionPromise, type DispatchActionPromise, @@ -764,6 +765,8 @@ const filterVoicedInAnnouncementChannelsPermission = options?.filterVoicedInAnnouncementChannelsPermission; const shouldMinimallyEncodePermissions = options?.minimallyEncodePermissions; + const shouldIncludeSpecialRoleFieldInRoles = + options?.includeSpecialRoleFieldInRoles; const filterThreadPermissions = _omitBy( (v, k) => @@ -878,9 +881,32 @@ 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( + 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 {