diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js --- a/lib/selectors/chat-selectors.js +++ b/lib/selectors/chat-selectors.js @@ -6,6 +6,7 @@ import _map from 'lodash/fp/map.js'; import _orderBy from 'lodash/fp/orderBy.js'; import * as React from 'react'; +import { useMemo } from 'react'; import { useSelector } from 'react-redux'; import { createSelector } from 'reselect'; import { createObjectSelector } from 'reselect-map'; @@ -585,6 +586,31 @@ userInfoInputArray, threadInfo, }: UseMessageListDataArgs): MessageListData { + const messageInfos = useSelector(messageInfoSelector); + + const containingThread = useSelector(state => { + if (!threadInfo || threadInfo.type !== threadTypes.SIDEBAR) { + return null; + } + return state.messageStore.threads[threadInfo.containingThreadID]; + }); + + const editedText = useMemo(() => { + const sourceMessageID = threadInfo?.sourceMessageID; + const threadMessageInfos = (containingThread?.messageIDs ?? []) + .map((messageID: string) => messageInfos[messageID]) + .filter(Boolean) + .filter( + message => + message.type === messageTypes.EDIT_MESSAGE && + message.targetMessageID === sourceMessageID, + ); + if (threadMessageInfos.length === 0) { + return null; + } + return threadMessageInfos[0].text; + }, [containingThread?.messageIDs, messageInfos, threadInfo?.sourceMessageID]); + const pendingSidebarSourceMessageInfo = useSelector(state => { const sourceMessageID = threadInfo?.sourceMessageID; if ( @@ -595,14 +621,24 @@ return null; } const thread = state.messageStore.threads[threadInfo.id]; - const messageInfos = messageInfoSelector(state); const shouldSourceBeAdded = !thread || (thread.startReached && thread.messageIDs.every( id => messageInfos[id]?.type !== messageTypes.SIDEBAR_SOURCE, )); - return shouldSourceBeAdded ? messageInfos[sourceMessageID] : null; + + if (!shouldSourceBeAdded) { + return null; + } + let result = messageInfos[sourceMessageID]; + if (result && result.type === messageTypes.TEXT && editedText) { + result = { + ...result, + text: editedText, + }; + } + return result; }); invariant(