diff --git a/native/chat/reaction-message-utils.js b/native/chat/reaction-message-utils.js --- a/native/chat/reaction-message-utils.js +++ b/native/chat/reaction-message-utils.js @@ -7,7 +7,15 @@ sendReactionMessage, sendReactionMessageActionTypes, } from 'lib/actions/message-actions'; +import { relationshipBlockedInEitherDirection } from 'lib/shared/relationship-utils'; +import { threadHasPermission } from 'lib/shared/thread-utils'; +import type { + RobotextMessageInfo, + ComposableMessageInfo, +} from 'lib/types/message-types'; +import { threadPermissions, type ThreadInfo } from 'lib/types/thread-types'; import type { BindServerCall, DispatchFunctions } from 'lib/utils/action-utils'; +import { useSelector } from 'lib/utils/redux-utils'; import type { TooltipRoute } from '../navigation/tooltip.react'; @@ -78,4 +86,29 @@ ); } -export { onPressReact }; +function useCanCreateReactionFromMessage( + threadInfo: ThreadInfo, + messageInfo: ComposableMessageInfo | RobotextMessageInfo, +): boolean { + const messageCreatorRelationship = useSelector( + state => + state.userStore.userInfos[messageInfo.creator.id]?.relationshipStatus, + ); + + if (!messageInfo.id) { + return false; + } + + const creatorRelationshipHasBlock = + messageCreatorRelationship && + relationshipBlockedInEitherDirection(messageCreatorRelationship); + + const hasPermission = threadHasPermission( + threadInfo, + threadPermissions.VOICED, + ); + + return hasPermission && !creatorRelationshipHasBlock; +} + +export { onPressReact, useCanCreateReactionFromMessage };