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 @@ -954,6 +954,50 @@ return threadIsWithBlockedUserOnly(threadInfo, viewerID, userInfos, options); } +function useThreadFrozenDueToViewerBlock( + threadInfo: ThreadInfo, + communityThreadInfo: ?ThreadInfo, + viewerID: ?string, + userInfos: UserInfos, +): boolean { + const communityThreadInfoArray = React.useMemo( + () => (communityThreadInfo ? [communityThreadInfo] : []), + [communityThreadInfo], + ); + const communityRootsMembersToRole = useCommunityRootMembersToRole( + communityThreadInfoArray, + ); + const memberToRole = React.useMemo( + () => communityRootsMembersToRole?.[communityThreadInfo?.id], + [communityRootsMembersToRole, communityThreadInfo?.id], + ); + + const memberHasAdminRole = React.useMemo( + () => + threadMembersWithoutAddedAdmin(threadInfo).some(m => + roleIsAdminRole(memberToRole?.[m.id]), + ), + [memberToRole, threadInfo], + ); + + return React.useMemo(() => { + if (memberHasAdminRole) { + return false; + } + + const options: ThreadIsWithBlockedUserOnlyOptions = { + checkOnlyViewerBlock: true, + skipMemberAdminRoleCheck: true, + }; + return threadIsWithBlockedUserOnly( + threadInfo, + viewerID, + userInfos, + options, + ); + }, [memberHasAdminRole, threadInfo, userInfos, viewerID]); +} + const threadTypeDescriptions: { [ThreadType]: string } = { [threadTypes.COMMUNITY_OPEN_SUBTHREAD]: 'Anybody in the parent channel can see an open subchannel.', @@ -1646,6 +1690,7 @@ filterOutDisabledPermissions, threadFrozenDueToBlock, threadFrozenDueToViewerBlock, + useThreadFrozenDueToViewerBlock, rawThreadInfoFromServerThreadInfo, threadUIName, threadInfoFromRawThreadInfo, diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js --- a/native/chat/chat-input-bar.react.js +++ b/native/chat/chat-input-bar.react.js @@ -60,7 +60,7 @@ checkIfDefaultMembersAreVoiced, draftKeyFromThreadID, threadActualMembers, - threadFrozenDueToViewerBlock, + useThreadFrozenDueToViewerBlock, useThreadHasPermission, viewerIsMember, } from 'lib/shared/thread-utils.js'; @@ -84,7 +84,6 @@ ClientThreadJoinRequest, ThreadJoinPayload, } from 'lib/types/thread-types.js'; -import { type UserInfos } from 'lib/types/user-types.js'; import { type DispatchActionPromise, useDispatchActionPromise, @@ -284,7 +283,6 @@ +joinThreadLoadingStatus: LoadingStatus, +threadCreationInProgress: boolean, +calendarQuery: () => CalendarQuery, - +userInfos: UserInfos, +colors: Colors, +styles: $ReadOnly, +onInputBarLayout?: (event: LayoutEvent) => mixed, @@ -299,7 +297,6 @@ +chatMentionSearchIndex: ?SentencePrefixSearchIndex, +chatMentionCandidates: ChatMentionCandidates, +parentThreadInfo: ?ThreadInfo, - +communityThreadInfo: ?ThreadInfo, +editedMessagePreview: ?MessagePreviewResult, +editedMessageInfo: ?MessageInfo, +editMessage: ( @@ -315,6 +312,7 @@ +typeaheadMatchedStrings: ?TypeaheadMatchedStrings, +currentUserIsVoiced: boolean, +currentUserCanJoin: boolean, + +threadFrozen: boolean, }; type State = { +text: string, @@ -701,12 +699,7 @@ if (this.shouldShowTextInput) { content = this.renderInput(); } else if ( - threadFrozenDueToViewerBlock( - this.props.threadInfo, - this.props.communityThreadInfo, - this.props.viewerID, - this.props.userInfos, - ) && + this.props.threadFrozen && threadActualMembers(this.props.threadInfo.members).length === 2 ) { content = ( @@ -1269,6 +1262,13 @@ community ? threadInfoSelector(state)[community] : null, ); + const threadFrozen = useThreadFrozenDueToViewerBlock( + props.threadInfo, + communityThreadInfo, + viewerID, + userInfos, + ); + const userMentionsCandidates = useUserMentionsCandidates( props.threadInfo, parentThreadInfo, @@ -1350,7 +1350,6 @@ joinThreadLoadingStatus={joinThreadLoadingStatus} threadCreationInProgress={threadCreationInProgress} calendarQuery={calendarQuery} - userInfos={userInfos} colors={colors} styles={styles} isActive={isActive} @@ -1363,7 +1362,6 @@ chatMentionSearchIndex={chatMentionSearchIndex} chatMentionCandidates={chatMentionCandidates} parentThreadInfo={parentThreadInfo} - communityThreadInfo={communityThreadInfo} editedMessagePreview={editedMessagePreview} editedMessageInfo={editedMessageInfo} editMessage={editMessage} @@ -1376,6 +1374,7 @@ typeaheadMatchedStrings={typeaheadMatchedStrings} currentUserIsVoiced={currentUserIsVoiced} currentUserCanJoin={currentUserCanJoin} + threadFrozen={threadFrozen} /> ); }