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 chatMessageInfoItemTargetableMessageInfo( + item: BaseChatMessageInfoItem, +): ComposableMessageInfo | RobotextMessageInfo { + return item.messageInfo; +} + function chatMessageItemHasNonViewerMessage( item: BaseChatMessageItem, viewerID: ?string, @@ -70,6 +76,7 @@ export { chatMessageItemKey, chatMessageInfoItemTimestamp, + chatMessageInfoItemTargetableMessageInfo, 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 { chatMessageInfoItemTargetableMessageInfo } 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 targetableMessageInfo = + chatMessageInfoItemTargetableMessageInfo(messageItem); const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage( threadInfo, - messageItem.messageInfo, + targetableMessageInfo, ); 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 { chatMessageInfoItemTargetableMessageInfo } from 'lib/shared/chat-message-item-utils.js'; import { useViewerAlreadySelectedMessageReactions, useCanCreateReactionFromMessage, @@ -66,14 +67,19 @@ }; }, [initialCoordinates.height, initialCoordinates.x, progress, windowWidth]); - const { messageInfo, threadInfo, reactions } = item; + const { threadInfo, reactions } = item; + const targetableMessageInfo = chatMessageInfoItemTargetableMessageInfo(item); const canCreateReactionFromMessage = useCanCreateReactionFromMessage( threadInfo, - messageInfo, + targetableMessageInfo, ); - const sendReaction = useSendReaction(messageInfo.id, threadInfo, reactions); + const sendReaction = useSendReaction( + targetableMessageInfo?.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, + chatMessageInfoItemTargetableMessageInfo, } from 'lib/shared/chat-message-item-utils.js'; import { useCanCreateSidebarFromMessage } from 'lib/shared/sidebar-utils.js'; @@ -62,12 +63,13 @@ } const styles = useStyles(unboundStyles); + const targetableMessageInfo = chatMessageInfoItemTargetableMessageInfo(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 { chatMessageInfoItemTargetableMessageInfo } 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 targetableMessageInfo = + chatMessageInfoItemTargetableMessageInfo(item); inlineEngagement = (
{ const createToggleMessagePinPromise = async () => { - invariant(messageInfo.id, 'messageInfo.id should be defined'); + invariant(targetableMessageID, 'targetable messageID should be defined'); const result = await callToggleMessagePin({ - messageID: messageInfo.id, + messageID: targetableMessageID, action: modalInfo.action, }); return ({ @@ -96,7 +99,7 @@ modalInfo, callToggleMessagePin, dispatchActionPromise, - messageInfo.id, + targetableMessageID, 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 { chatMessageInfoItemTargetableMessageInfo } 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,12 @@ }; }, [emojiKeyboardPosition]); - const sendReaction = useSendReaction(messageInfo.id, threadInfo, reactions); + const targetableMessageInfo = chatMessageInfoItemTargetableMessageInfo(item); + const sendReaction = useSendReaction( + targetableMessageInfo?.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, + chatMessageInfoItemTargetableMessageInfo, +} 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,13 @@ threadInfo: ThreadInfo, ): ?MessageTooltipAction { const { pushModal } = useModalContext(); - const { messageInfo, isPinned } = item; + const { isPinned } = item; - const canTogglePin = useCanToggleMessagePin(messageInfo, threadInfo); + const targetableMessageInfo = chatMessageInfoItemTargetableMessageInfo(item); + const canTogglePin = useCanToggleMessagePin( + targetableMessageInfo, + threadInfo, + ); const inputState = React.useContext(InputStateContext);