From ba865e6a68b12a22996ddf924223041b346c56cd Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 15 May 2021 02:46:08 +0300 Subject: [PATCH] Message List: Fix flickering sticky dates background; Middle Header: Small refactoring --- src/components/middle/MiddleColumn.tsx | 27 ++++++------ src/components/middle/MiddleHeader.tsx | 60 +++++++++++++------------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 323c1b732..3b8719f3a 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -306,12 +306,20 @@ export default memo(withGlobal( const isCustomBackgroundColor = Boolean((customBackground || '').match(/^#[a-f\d]{6,8}$/i)); const currentMessageList = selectCurrentMessageList(global); const { chats: { listIds } } = global; + + const state: StateProps = { + customBackground, + patternColor, + isCustomBackgroundColor, + isRightColumnShown: selectIsRightColumnShown(global), + isBackgroundBlurred, + isMobileSearchActive: Boolean(IS_MOBILE_SCREEN && selectCurrentTextSearch(global)), + isSelectModeActive: selectIsInSelectMode(global), + animationLevel: global.settings.byKey.animationLevel, + }; + if (!currentMessageList || !listIds.active) { - return { - customBackground, - isBackgroundBlurred, - isCustomBackgroundColor, - }; + return state; } const { chatId, threadId, type: messageListType } = currentMessageList; @@ -324,6 +332,7 @@ export default memo(withGlobal( const isPinnedMessageList = messageListType === 'pinned'; return { + ...state, chatId, threadId, messageListType, @@ -336,14 +345,6 @@ export default memo(withGlobal( || Boolean(pinnedIds && pinnedIds.length) || Boolean(audioChatId && audioMessageId) ), - customBackground, - patternColor, - isCustomBackgroundColor, - isRightColumnShown: selectIsRightColumnShown(global), - isBackgroundBlurred, - isMobileSearchActive: Boolean(IS_MOBILE_SCREEN && selectCurrentTextSearch(global)), - isSelectModeActive: selectIsInSelectMode(global), - animationLevel: global.settings.byKey.animationLevel, }; }, (setGlobal, actions): DispatchProps => pick(actions, [ diff --git a/src/components/middle/MiddleHeader.tsx b/src/components/middle/MiddleHeader.tsx index 0195ed0bf..f1e7bfcc0 100644 --- a/src/components/middle/MiddleHeader.tsx +++ b/src/components/middle/MiddleHeader.tsx @@ -429,7 +429,7 @@ export default memo(withGlobal( } } - let state: StateProps = { + const state: StateProps = { typingStatus, isLeftColumnShown, isRightColumnShown: selectIsRightColumnShown(global), @@ -445,36 +445,38 @@ export default memo(withGlobal( }; const messagesById = selectChatMessages(global, chatId); - if (messageListType === 'thread' && messagesById) { - if (threadId === MAIN_THREAD_ID) { - const pinnedMessageIds = selectPinnedIds(global, chatId); + if (messageListType !== 'thread' || !messagesById) { + return state; + } - if (pinnedMessageIds && pinnedMessageIds.length) { - const firstPinnedMessage = messagesById[pinnedMessageIds[0]]; - const { - canUnpin, - } = (firstPinnedMessage && selectAllowedMessageActions(global, firstPinnedMessage, threadId)) || {}; - state = { - ...state, - pinnedMessageIds, - messagesById, - canUnpin, - }; - } - } else { - const pinnedMessageId = selectThreadTopMessageId(global, chatId, threadId); - const message = pinnedMessageId ? selectChatMessage(global, chatId, pinnedMessageId) : undefined; - const sender = message ? selectForwardedSender(global, message) : undefined; - const topMessageTitle = sender ? getSenderTitle(sender) : undefined; + Object.assign(state, { messagesById }); - state = { - ...state, - pinnedMessageIds: pinnedMessageId, - messagesById, - canUnpin: false, - topMessageTitle, - }; - } + if (threadId !== MAIN_THREAD_ID) { + const pinnedMessageId = selectThreadTopMessageId(global, chatId, threadId); + const message = pinnedMessageId ? selectChatMessage(global, chatId, pinnedMessageId) : undefined; + const sender = message ? selectForwardedSender(global, message) : undefined; + const topMessageTitle = sender ? getSenderTitle(sender) : undefined; + + return { + ...state, + pinnedMessageIds: pinnedMessageId, + canUnpin: false, + topMessageTitle, + }; + } + + const pinnedMessageIds = selectPinnedIds(global, chatId); + if (pinnedMessageIds && pinnedMessageIds.length) { + const firstPinnedMessage = messagesById[pinnedMessageIds[0]]; + const { + canUnpin, + } = (firstPinnedMessage && selectAllowedMessageActions(global, firstPinnedMessage, threadId)) || {}; + + return { + ...state, + pinnedMessageIds, + canUnpin, + }; } return state;