From 357eef783b32b6d38b98f631e051363dd4c1af6c Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 4 Feb 2023 03:02:46 +0100 Subject: [PATCH] [Perf] Message: Do not depend on `sender` when not needed --- src/components/middle/message/Message.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 639d0b1d3..6c88eca76 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -84,6 +84,7 @@ import { getMessageSingleCustomEmoji, hasMessageText, isChatGroup, + getMessageLocation, } from '../../../global/helpers'; import buildClassName from '../../../util/buildClassName'; import { @@ -1289,11 +1290,12 @@ export default memo(withGlobal( const messageTopic = hasTopicChip ? (selectTopicFromMessage(global, message) || chat?.topics?.[GENERAL_TOPIC_ID]) : undefined; + const isLocation = Boolean(getMessageLocation(message)); + return { theme: selectTheme(global), chatUsernames, forceSenderName, - sender, canShowSender, originSender, botSender, @@ -1335,9 +1337,6 @@ export default memo(withGlobal( defaultReaction: isMessageLocal(message) ? undefined : selectDefaultReaction(global, chatId), activeReactions: reactionMessage && activeReactions[reactionMessage.id], activeEmojiInteractions, - ...(isOutgoing && { outgoingStatus: selectOutgoingStatus(global, message, messageListType === 'scheduled') }), - ...(typeof uploadProgress === 'number' && { uploadProgress }), - ...(isFocused && { focusDirection, noFocusHighlight, isResizingContainer }), hasUnreadReaction, isTranscribing: transcriptionId !== undefined && global.transcriptions[transcriptionId]?.isPending, transcribedText: transcriptionId !== undefined ? global.transcriptions[transcriptionId]?.text : undefined, @@ -1347,6 +1346,10 @@ export default memo(withGlobal( messageTopic, genericEffects: global.genericEmojiEffects, hasTopicChip, + ...((canShowSender || isLocation) && { sender }), + ...(isOutgoing && { outgoingStatus: selectOutgoingStatus(global, message, messageListType === 'scheduled') }), + ...(typeof uploadProgress === 'number' && { uploadProgress }), + ...(isFocused && { focusDirection, noFocusHighlight, isResizingContainer }), }; }, )(Message));