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 @@ -26,7 +26,11 @@ import ashoat from '../facts/ashoat.js'; import genesis from '../facts/genesis.js'; import { useLoggedInUserInfo } from '../hooks/account-hooks.js'; -import { hasPermission } from '../permissions/minimally-encoded-thread-permissions.js'; +import { + hasPermission, + permissionsToBitmaskHex, + threadPermissionsFromBitmaskHex, +} from '../permissions/minimally-encoded-thread-permissions.js'; import { permissionLookup, getAllThreadPermissions, @@ -57,6 +61,7 @@ MinimallyEncodedMemberInfo, MinimallyEncodedRawThreadInfo, MinimallyEncodedRoleInfo, + MinimallyEncodedThreadCurrentUserInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; import { @@ -942,6 +947,28 @@ }; } +function getMinimallyEncodedCurrentUser( + threadInfo: MinimallyEncodedRawThreadInfo, + viewerID: ?string, + userInfos: UserInfos, +): MinimallyEncodedThreadCurrentUserInfo { + if (!threadFrozenDueToBlock(threadInfo, viewerID, userInfos)) { + return threadInfo.currentUser; + } + const decodedPermissions = threadPermissionsFromBitmaskHex( + threadInfo.currentUser.permissions, + ); + const updatedPermissions = { + ...decodedPermissions, + ...disabledPermissions, + }; + const encodedUpdatedPermissions = permissionsToBitmaskHex(updatedPermissions); + return { + ...threadInfo.currentUser, + permissions: encodedUpdatedPermissions, + }; +} + function threadIsWithBlockedUserOnly( threadInfo: RawThreadInfo | ThreadInfo | MinimallyEncodedRawThreadInfo, viewerID: ?string, @@ -1767,6 +1794,7 @@ pendingThreadType, createRealThreadFromPendingThread, getCurrentUser, + getMinimallyEncodedCurrentUser, threadFrozenDueToBlock, threadFrozenDueToViewerBlock, rawThreadInfoFromServerThreadInfo,