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,18 @@ const onToggleFocus = React.useCallback(() => {}, []); + const item = modifyItemForResultScreen(props.item); + invariant( + item.messageShapeType !== 'robotext' && item.itemType !== 'loader', + 'should not be robotext or 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/utils.js b/native/chat/utils.js --- a/native/chat/utils.js +++ b/native/chat/utils.js @@ -412,6 +412,45 @@ return messageKey(item.messageInfo); } +function modifyItemForResultScreen( + item: ChatMessageItemWithHeight, +): ChatMessageItemWithHeight { + invariant( + item.messageShapeType !== 'robotext' && item.itemType !== 'loader', + 'should not be robotext or loader', + ); + + 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 +460,5 @@ isMessageTooltipKey, useContentAndHeaderOpacity, useDeliveryIconOpacity, + modifyItemForResultScreen, };