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 @@ -2,6 +2,7 @@ import invariant from 'invariant'; import _find from 'lodash/fp/find.js'; +import _omitBy from 'lodash/fp/omitBy.js'; import * as React from 'react'; import { generatePendingThreadColor } from './color-utils.js'; @@ -710,6 +711,15 @@ const filterDetailedThreadEditPermissions = options?.filterDetailedThreadEditPermissions; + const filterThreadPermissions = _omitBy( + (v, k) => + filterDetailedThreadEditPermissions && + [ + threadPermissions.EDIT_THREAD_COLOR, + threadPermissions.EDIT_THREAD_DESCRIPTION, + ].includes(k), + ); + const members = []; let currentUser; for (const serverMember of serverThreadInfo.members) { @@ -728,10 +738,9 @@ ) { continue; } - const memberPermissions = filterThreadEditDetailedPermissions( - serverMember.permissions, - filterDetailedThreadEditPermissions, - ); + + const memberPermissions = filterThreadPermissions(serverMember.permissions); + members.push({ id: serverMember.id, role: serverMember.role, @@ -752,9 +761,8 @@ if (currentUser) { currentUserPermissions = currentUser.permissions; } else { - currentUserPermissions = filterThreadEditDetailedPermissions( + currentUserPermissions = filterThreadPermissions( getAllThreadPermissions(null, serverThreadInfo.id), - filterDetailedThreadEditPermissions, ); currentUser = { role: null, @@ -815,18 +823,6 @@ return rawThreadInfo; } -function filterThreadEditDetailedPermissions( - permissions: ThreadPermissionsInfo, - shouldFilter: ?boolean, -): ThreadPermissionsInfo { - if (!shouldFilter) { - return permissions; - } - const { edit_thread_color, edit_thread_description, ...newPermissions } = - permissions; - return newPermissions; -} - function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity { if (threadInfo.name) { return firstLine(threadInfo.name); @@ -1571,7 +1567,6 @@ threadFrozenDueToBlock, threadFrozenDueToViewerBlock, rawThreadInfoFromServerThreadInfo, - filterThreadEditDetailedPermissions, threadUIName, threadInfoFromRawThreadInfo, threadTypeDescriptions,