diff --git a/lib/shared/reaction-utils.js b/lib/shared/reaction-utils.js --- a/lib/shared/reaction-utils.js +++ b/lib/shared/reaction-utils.js @@ -3,6 +3,14 @@ import invariant from 'invariant'; import type { MessageReactionInfo } from '../selectors/chat-selectors'; +import type { + RobotextMessageInfo, + ComposableMessageInfo, +} from '../types/message-types'; +import { threadPermissions, type ThreadInfo } from '../types/thread-types'; +import { useSelector } from '../utils/redux-utils'; +import { relationshipBlockedInEitherDirection } from './relationship-utils'; +import { threadHasPermission } from './thread-utils'; function stringForReactionList( reactions: $ReadOnlyMap, @@ -24,4 +32,33 @@ return reactionText.join(' '); } -export { stringForReactionList }; +function useCanCreateReactionFromMessage( + threadInfo: ThreadInfo, + targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo, +): boolean { + const targetMessageCreatorRelationship = useSelector( + state => + state.userStore.userInfos[targetMessageInfo.creator.id] + ?.relationshipStatus, + ); + + if ( + !targetMessageInfo.id || + threadInfo.sourceMessageID === targetMessageInfo.id + ) { + return false; + } + + const creatorRelationshipHasBlock = + targetMessageCreatorRelationship && + relationshipBlockedInEitherDirection(targetMessageCreatorRelationship); + + const hasPermission = threadHasPermission( + threadInfo, + threadPermissions.VOICED, + ); + + return hasPermission && !creatorRelationshipHasBlock; +} + +export { stringForReactionList, useCanCreateReactionFromMessage }; diff --git a/native/chat/multimedia-message.react.js b/native/chat/multimedia-message.react.js --- a/native/chat/multimedia-message.react.js +++ b/native/chat/multimedia-message.react.js @@ -10,6 +10,7 @@ import { StyleSheet, View } from 'react-native'; import { messageKey } from 'lib/shared/message-utils'; +import { useCanCreateReactionFromMessage } from 'lib/shared/reaction-utils'; import { useCanCreateSidebarFromMessage } from 'lib/shared/thread-utils'; import type { MediaInfo } from 'lib/types/media-types'; @@ -31,7 +32,6 @@ getMediaKey, multimediaMessageSendFailed, } from './multimedia-message-utils'; -import { useCanCreateReactionFromMessage } from './reaction-message-utils'; import { getMessageTooltipKey } from './utils'; type BaseProps = { 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,15 +7,7 @@ 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'; @@ -92,33 +84,4 @@ ); } -function useCanCreateReactionFromMessage( - threadInfo: ThreadInfo, - targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo, -): boolean { - const targetMessageCreatorRelationship = useSelector( - state => - state.userStore.userInfos[targetMessageInfo.creator.id] - ?.relationshipStatus, - ); - - if ( - !targetMessageInfo.id || - threadInfo.sourceMessageID === targetMessageInfo.id - ) { - return false; - } - - const creatorRelationshipHasBlock = - targetMessageCreatorRelationship && - relationshipBlockedInEitherDirection(targetMessageCreatorRelationship); - - const hasPermission = threadHasPermission( - threadInfo, - threadPermissions.VOICED, - ); - - return hasPermission && !creatorRelationshipHasBlock; -} - -export { onPressReact, useCanCreateReactionFromMessage }; +export { onPressReact }; diff --git a/native/chat/robotext-message.react.js b/native/chat/robotext-message.react.js --- a/native/chat/robotext-message.react.js +++ b/native/chat/robotext-message.react.js @@ -5,6 +5,7 @@ import { View } from 'react-native'; import { messageKey } from 'lib/shared/message-utils'; +import { useCanCreateReactionFromMessage } from 'lib/shared/reaction-utils'; import { useCanCreateSidebarFromMessage } from 'lib/shared/thread-utils'; import { ChatContext } from '../chat/chat-context'; @@ -21,7 +22,6 @@ import type { ChatNavigationProp } from './chat.react'; import { InlineSidebar } from './inline-sidebar.react'; import { InnerRobotextMessage } from './inner-robotext-message.react'; -import { useCanCreateReactionFromMessage } from './reaction-message-utils'; import { Timestamp } from './timestamp.react'; import { getMessageTooltipKey, useContentAndHeaderOpacity } from './utils'; diff --git a/native/chat/text-message.react.js b/native/chat/text-message.react.js --- a/native/chat/text-message.react.js +++ b/native/chat/text-message.react.js @@ -5,6 +5,7 @@ import { View } from 'react-native'; import { messageKey } from 'lib/shared/message-utils'; +import { useCanCreateReactionFromMessage } from 'lib/shared/reaction-utils'; import { threadHasPermission, useCanCreateSidebarFromMessage, @@ -29,7 +30,6 @@ MessagePressResponderContext, type MessagePressResponderContextType, } from './message-press-responder-context'; -import { useCanCreateReactionFromMessage } from './reaction-message-utils'; import textMessageSendFailed from './text-message-send-failed'; import { getMessageTooltipKey } from './utils';