diff --git a/native/chat/message-result.react.js b/native/chat/message-result.react.js --- a/native/chat/message-result.react.js +++ b/native/chat/message-result.react.js @@ -1,5 +1,6 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; import { Text, View } from 'react-native'; import { ScrollView } from 'react-native-gesture-handler'; @@ -10,6 +11,7 @@ import type { ChatNavigationProp } from './chat.react'; import { MessageListContextProvider } from './message-list-types.js'; import { Message } from './message.react.js'; +import { modifyItemForResultScreen } from './utils.js'; import type { AppNavigationProp } from '../navigation/app-navigator.react'; import type { NavigationRoute } from '../navigation/route-names'; import { useStyles } from '../themes/colors.js'; @@ -33,12 +35,16 @@ const onToggleFocus = React.useCallback(() => {}, []); + const item = modifyItemForResultScreen(props.item); + + invariant(item.itemType !== 'loader', 'should not be loader'); + return ( - measuredMessages.map(item => { - invariant(item.itemType !== 'loader', 'should not be loader'); - invariant( - item.messageShapeType !== 'robotext', - 'should not be robotext', - ); - - if (item.messageShapeType === 'multimedia') { - return { - ...item, - startsConversation: false, - startsCluster: true, - endsCluster: true, - messageInfo: { - ...item.messageInfo, - creator: { - ...item.messageInfo.creator, - isViewer: false, - }, - }, - }; - } - - return { - ...item, - startsConversation: false, - startsCluster: true, - endsCluster: true, - messageInfo: { - ...item.messageInfo, - creator: { - ...item.messageInfo.creator, - isViewer: false, - }, - }, - }; - }), - [measuredMessages], - ); - const onLayout = React.useCallback(() => { scrollViewContainerRef.current?.measure( (x, y, width, height, pageX, pageY) => { @@ -177,17 +135,21 @@ const messageResultsToDisplay = React.useMemo( () => - modifiedItems.map(item => ( - - )), - [modifiedItems, threadInfo, navigation, route, messageVerticalBounds], + measuredMessages.map(item => { + invariant(item.itemType !== 'loader', 'should not be loader'); + + return ( + + ); + }), + [measuredMessages, threadInfo, navigation, route, messageVerticalBounds], ); return ( diff --git a/native/chat/toggle-pin-modal.react.js b/native/chat/toggle-pin-modal.react.js --- a/native/chat/toggle-pin-modal.react.js +++ b/native/chat/toggle-pin-modal.react.js @@ -15,6 +15,7 @@ } from 'lib/utils/action-utils.js'; import MessageResult from './message-result.react.js'; +import { modifyItemForResultScreen } from './utils.js'; import Button from '../components/button.react.js'; import Modal from '../components/modal.react.js'; import type { AppNavigationProp } from '../navigation/app-navigator.react.js'; @@ -65,44 +66,12 @@ }; }, [isPinned, styles.pinButton, styles.removePinButton]); - const modifiedItem = React.useMemo(() => { - // The if / else if / else conditional is for Flow - if (item.messageShapeType === 'robotext') { - return item; - } else if (item.messageShapeType === 'multimedia') { - return { - ...item, - threadCreatedFromMessage: undefined, - reactions: {}, - startsConversation: false, - startsCluster: true, - endsCluster: true, - messageInfo: { - ...item.messageInfo, - creator: { - ...item.messageInfo.creator, - isViewer: false, - }, - }, - }; - } else { - return { - ...item, - threadCreatedFromMessage: undefined, - reactions: {}, - startsConversation: false, - startsCluster: true, - endsCluster: true, - messageInfo: { - ...item.messageInfo, - creator: { - ...item.messageInfo.creator, - isViewer: false, - }, - }, - }; - } - }, [item]); + const modifiedItem = React.useMemo( + () => modifyItemForResultScreen(item), + [item], + ); + + invariant(modifiedItem.itemType !== 'loader', 'should not be loader'); const createToggleMessagePinPromise = React.useCallback(async () => { invariant(messageInfo.id, 'messageInfo.id should be defined'); diff --git a/native/chat/utils.js b/native/chat/utils.js --- a/native/chat/utils.js +++ b/native/chat/utils.js @@ -412,6 +412,46 @@ return messageKey(item.messageInfo); } +function modifyItemForResultScreen( + item: ChatMessageItemWithHeight, +): ChatMessageItemWithHeight { + invariant(item.itemType !== 'loader', 'should not be loader'); + + if (item.messageShapeType === 'robotext') { + return item; + } + + if (item.messageShapeType === 'multimedia') { + return { + ...item, + startsConversation: false, + startsCluster: true, + endsCluster: true, + messageInfo: { + ...item.messageInfo, + creator: { + ...item.messageInfo.creator, + isViewer: false, + }, + }, + }; + } + + return { + ...item, + startsConversation: false, + startsCluster: true, + endsCluster: true, + messageInfo: { + ...item.messageInfo, + creator: { + ...item.messageInfo.creator, + isViewer: false, + }, + }, + }; +} + export { chatMessageItemKey, chatMessageItemHeight, @@ -421,4 +461,5 @@ isMessageTooltipKey, useContentAndHeaderOpacity, useDeliveryIconOpacity, + modifyItemForResultScreen, };