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 @@ -585,6 +585,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 pendingSidebarEditMessageInfo = React.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]; + }, [threadInfo, containingThread, messageInfos]); + const pendingSidebarSourceMessageInfo = useSelector(state => { const sourceMessageID = threadInfo?.sourceMessageID; if ( @@ -595,7 +620,6 @@ return null; } const thread = state.messageStore.threads[threadInfo.id]; - const messageInfos = messageInfoSelector(state); const shouldSourceBeAdded = !thread || (thread.startReached && @@ -611,11 +635,16 @@ 'sidebars can not be created from sidebar_source message', ); - const additionalMessages = React.useMemo( - () => - pendingSidebarSourceMessageInfo ? [pendingSidebarSourceMessageInfo] : [], - [pendingSidebarSourceMessageInfo], - ); + const additionalMessages = React.useMemo(() => { + if (!pendingSidebarSourceMessageInfo) { + return []; + } + const result = [pendingSidebarSourceMessageInfo]; + if (pendingSidebarEditMessageInfo) { + result.push(pendingSidebarEditMessageInfo); + } + return result; + }, [pendingSidebarSourceMessageInfo, pendingSidebarEditMessageInfo]); const boundMessageListData = useSelector( messageListData(threadInfo?.id, additionalMessages), ); diff --git a/lib/shared/edit-messages-utils.js b/lib/shared/edit-messages-utils.js --- a/lib/shared/edit-messages-utils.js +++ b/lib/shared/edit-messages-utils.js @@ -3,7 +3,7 @@ import invariant from 'invariant'; import * as React from 'react'; -import { threadHasPermission } from './thread-utils.js'; +import { threadIsPending, threadHasPermission } from './thread-utils.js'; import { sendEditMessageActionTypes, sendEditMessage, @@ -76,4 +76,15 @@ return hasPermission; } -export { useCanEditMessage, useEditMessage }; +function getMessageLabel( + hasBeenEdited: ?boolean, + threadInfo: ThreadInfo, +): ?string { + const isPending = threadIsPending(threadInfo.id); + if (hasBeenEdited && !isPending) { + return 'Edited'; + } + return null; +} + +export { useCanEditMessage, useEditMessage, getMessageLabel }; diff --git a/native/chat/composed-message.react.js b/native/chat/composed-message.react.js --- a/native/chat/composed-message.react.js +++ b/native/chat/composed-message.react.js @@ -6,6 +6,7 @@ import { StyleSheet, View } from 'react-native'; import Animated from 'react-native-reanimated'; +import { getMessageLabel } from 'lib/shared/edit-messages-utils.js'; import { createMessageReply } from 'lib/shared/message-utils.js'; import { assertComposableMessageType } from 'lib/types/message-types.js'; @@ -163,13 +164,13 @@ ); let inlineEngagement = null; + const label = getMessageLabel(hasBeenEdited, item.threadInfo); if ( item.threadCreatedFromMessage || Object.keys(item.reactions).length > 0 || - hasBeenEdited + label ) { const positioning = isViewer ? 'right' : 'left'; - const label = hasBeenEdited ? 'Edited' : null; inlineEngagement = ( 0) { height += inlineEngagementStyle.height + inlineEngagementStyle.marginTop + inlineEngagementStyle.marginBottom; - } else if (item.hasBeenEdited) { + } else if (label) { height += editedLabelHeight; } return height; diff --git a/web/chat/composed-message.react.js b/web/chat/composed-message.react.js --- a/web/chat/composed-message.react.js +++ b/web/chat/composed-message.react.js @@ -10,6 +10,7 @@ import { useStringForUser } from 'lib/hooks/ens-cache.js'; import { type ChatMessageInfoItem } from 'lib/selectors/chat-selectors.js'; +import { getMessageLabel } from 'lib/shared/edit-messages-utils.js'; import { assertComposableMessageType } from 'lib/types/message-types.js'; import { type ThreadInfo } from 'lib/types/thread-types.js'; @@ -131,13 +132,13 @@ } let inlineEngagement = null; + const label = getMessageLabel(hasBeenEdited, threadInfo); if ( (this.props.containsInlineEngagement && item.threadCreatedFromMessage) || Object.keys(item.reactions).length > 0 || - hasBeenEdited + label ) { const positioning = isViewer ? 'right' : 'left'; - const label = hasBeenEdited ? 'Edited' : null; inlineEngagement = (