diff --git a/lib/shared/chat-message-item-utils.js b/lib/shared/chat-message-item-utils.js --- a/lib/shared/chat-message-item-utils.js +++ b/lib/shared/chat-message-item-utils.js @@ -40,6 +40,12 @@ return longAbsoluteDate(item.messageInfo.time); } +function chatMessageItemEngagementTargetMessageInfo( + item: BaseChatMessageInfoItem, +): ComposableMessageInfo | RobotextMessageInfo { + return item.messageInfo; +} + function chatMessageItemHasNonViewerMessage( item: BaseChatMessageItem, viewerID: ?string, @@ -70,6 +76,7 @@ export { chatMessageItemKey, chatMessageInfoItemTimestamp, + chatMessageItemEngagementTargetMessageInfo, chatMessageItemHasNonViewerMessage, chatMessageItemHasEngagement, }; diff --git a/lib/shared/sidebar-utils.js b/lib/shared/sidebar-utils.js --- a/lib/shared/sidebar-utils.js +++ b/lib/shared/sidebar-utils.js @@ -13,6 +13,7 @@ userIsMember, } from './thread-utils.js'; import type { ChatMessageInfoItem } from '../selectors/chat-selectors.js'; +import { chatMessageItemEngagementTargetMessageInfo } from '../shared/chat-message-item-utils.js'; import { messageTypes } from '../types/message-types-enum.js'; import type { RobotextMessageInfo, @@ -229,9 +230,11 @@ threadInfo: ThreadInfo, messageItem: ChatMessageInfoItem, ): boolean { + const engagementTargetMessageInfo = + chatMessageItemEngagementTargetMessageInfo(messageItem); const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage( threadInfo, - messageItem.messageInfo, + engagementTargetMessageInfo, ); return !!messageItem.threadCreatedFromMessage || canCreateSidebarFromMessage; } diff --git a/native/chat/robotext-message-tooltip-button.react.js b/native/chat/robotext-message-tooltip-button.react.js --- a/native/chat/robotext-message-tooltip-button.react.js +++ b/native/chat/robotext-message-tooltip-button.react.js @@ -3,6 +3,7 @@ import * as React from 'react'; import Animated from 'react-native-reanimated'; +import { chatMessageItemEngagementTargetMessageInfo } from 'lib/shared/chat-message-item-utils.js'; import { useViewerAlreadySelectedMessageReactions, useCanCreateReactionFromMessage, @@ -66,14 +67,20 @@ }; }, [initialCoordinates.height, initialCoordinates.x, progress, windowWidth]); - const { messageInfo, threadInfo, reactions } = item; + const { threadInfo, reactions } = item; + const engagementTargetMessageInfo = + chatMessageItemEngagementTargetMessageInfo(item); const canCreateReactionFromMessage = useCanCreateReactionFromMessage( threadInfo, - messageInfo, + engagementTargetMessageInfo, ); - const sendReaction = useSendReaction(messageInfo.id, threadInfo, reactions); + const sendReaction = useSendReaction( + engagementTargetMessageInfo?.id, + threadInfo, + reactions, + ); const [emojiPickerOpen, setEmojiPickerOpen] = React.useState(false); const openEmojiPicker = React.useCallback(() => { 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 @@ -7,6 +7,7 @@ import { chatMessageItemKey, chatMessageItemHasEngagement, + chatMessageItemEngagementTargetMessageInfo, } from 'lib/shared/chat-message-item-utils.js'; import { useCanCreateSidebarFromMessage } from 'lib/shared/sidebar-utils.js'; @@ -62,12 +63,14 @@ } const styles = useStyles(unboundStyles); + const engagementTargetMessageInfo = + chatMessageItemEngagementTargetMessageInfo(item); let inlineEngagement = null; if (chatMessageItemHasEngagement(item, item.threadInfo.id)) { inlineEngagement = ( { diff --git a/web/chat/robotext-message.react.js b/web/chat/robotext-message.react.js --- a/web/chat/robotext-message.react.js +++ b/web/chat/robotext-message.react.js @@ -5,6 +5,7 @@ import { type RobotextChatMessageInfoItem } from 'lib/selectors/chat-selectors.js'; import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; +import { chatMessageItemEngagementTargetMessageInfo } from 'lib/shared/chat-message-item-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; import { @@ -41,10 +42,12 @@ const { item, threadInfo } = props; const { threadCreatedFromMessage, reactions } = item; if (threadCreatedFromMessage || Object.keys(reactions).length > 0) { + const engagementTargetMessageInfo = + chatMessageItemEngagementTargetMessageInfo(item); inlineEngagement = (
{ const createToggleMessagePinPromise = async () => { - invariant(messageInfo.id, 'messageInfo.id should be defined'); + invariant( + engagementTargetMessageID, + 'engagement target messageID should be defined', + ); const result = await callToggleMessagePin({ - messageID: messageInfo.id, + messageID: engagementTargetMessageID, action: modalInfo.action, }); return ({ @@ -96,7 +103,7 @@ modalInfo, callToggleMessagePin, dispatchActionPromise, - messageInfo.id, + engagementTargetMessageID, popModal, ]); diff --git a/web/tooltips/message-tooltip.react.js b/web/tooltips/message-tooltip.react.js --- a/web/tooltips/message-tooltip.react.js +++ b/web/tooltips/message-tooltip.react.js @@ -6,6 +6,7 @@ import * as React from 'react'; import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors.js'; +import { chatMessageItemEngagementTargetMessageInfo } from 'lib/shared/chat-message-item-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import css from './message-tooltip.css'; @@ -42,7 +43,7 @@ item, threadInfo, } = props; - const { messageInfo, reactions } = item; + const { reactions } = item; const { alignment = 'left' } = tooltipPositionStyle; @@ -169,7 +170,13 @@ }; }, [emojiKeyboardPosition]); - const sendReaction = useSendReaction(messageInfo.id, threadInfo, reactions); + const engagementTargetMessageInfo = + chatMessageItemEngagementTargetMessageInfo(item); + const sendReaction = useSendReaction( + engagementTargetMessageInfo?.id, + threadInfo, + reactions, + ); const onEmojiSelect = React.useCallback( (emoji: { +native: string, ... }) => { diff --git a/web/tooltips/tooltip-action-utils.js b/web/tooltips/tooltip-action-utils.js --- a/web/tooltips/tooltip-action-utils.js +++ b/web/tooltips/tooltip-action-utils.js @@ -10,7 +10,10 @@ ChatMessageInfoItem, ReactionInfo, } from 'lib/selectors/chat-selectors.js'; -import { chatMessageInfoItemTimestamp } from 'lib/shared/chat-message-item-utils.js'; +import { + chatMessageInfoItemTimestamp, + chatMessageItemEngagementTargetMessageInfo, +} from 'lib/shared/chat-message-item-utils.js'; import { useCanEditMessage } from 'lib/shared/edit-messages-utils.js'; import { createMessageReply } from 'lib/shared/message-utils.js'; import { useCanCreateReactionFromMessage } from 'lib/shared/reaction-utils.js'; @@ -280,9 +283,14 @@ threadInfo: ThreadInfo, ): ?MessageTooltipAction { const { pushModal } = useModalContext(); - const { messageInfo, isPinned } = item; + const { isPinned } = item; - const canTogglePin = useCanToggleMessagePin(messageInfo, threadInfo); + const engagementTargetMessageInfo = + chatMessageItemEngagementTargetMessageInfo(item); + const canTogglePin = useCanToggleMessagePin( + engagementTargetMessageInfo, + threadInfo, + ); const inputState = React.useContext(InputStateContext);