Skip to content

Commit

Permalink
[lib] Update checkIfDefaultMembersAreVoiced to handle `MinimallyEnc…
Browse files Browse the repository at this point in the history
…odedThreadInfo`

Summary: IF `RoleInfo` is `minimallyEncoded`, decode the `permissions` and then proceed with truthiness check.

Test Plan: Flow

Reviewers: ashoat, ginsu, tomek, rohan

Reviewed By: ashoat

Differential Revision: https://phab.comm.dev/D9889
  • Loading branch information
atulsmadhugiri committed Nov 15, 2023
1 parent edc5a06 commit 591adc4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/shared/thread-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import type {
MinimallyEncodedThreadCurrentUserInfo,
MinimallyEncodedThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import { decodeMinimallyEncodedRoleInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { userRelationshipStatus } from '../types/relationship-types.js';
import {
threadPermissionPropagationPrefixes,
Expand Down Expand Up @@ -1480,7 +1481,9 @@ function useSidebarExistsOrCanBeCreated(
return !!messageItem.threadCreatedFromMessage || canCreateSidebarFromMessage;
}

function checkIfDefaultMembersAreVoiced(threadInfo: ThreadInfo): boolean {
function checkIfDefaultMembersAreVoiced(
threadInfo: ThreadInfo | MinimallyEncodedThreadInfo,
): boolean {
const defaultRoleID = Object.keys(threadInfo.roles).find(
roleID => threadInfo.roles[roleID].isDefault,
);
Expand All @@ -1489,7 +1492,11 @@ function checkIfDefaultMembersAreVoiced(threadInfo: ThreadInfo): boolean {
'all threads should have a default role',
);
const defaultRole = threadInfo.roles[defaultRoleID];
return !!defaultRole.permissions[threadPermissions.VOICED];
const defaultRolePermissions = defaultRole.minimallyEncoded
? decodeMinimallyEncodedRoleInfo(defaultRole).permissions
: defaultRole.permissions;

return !!defaultRolePermissions[threadPermissions.VOICED];
}

const draftKeySuffix = '/message_composer';
Expand Down

0 comments on commit 591adc4

Please sign in to comment.