Message List: Fix flickering sticky dates background; Middle Header: Small refactoring

This commit is contained in:
Alexander Zinchuk 2021-05-15 02:46:08 +03:00
parent 18aeb7abe7
commit ba865e6a68
2 changed files with 45 additions and 42 deletions

View File

@ -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, [

View File

@ -429,7 +429,7 @@ export default memo(withGlobal<OwnProps>(
}
}
let state: StateProps = {
const state: StateProps = {
typingStatus,
isLeftColumnShown,
isRightColumnShown: selectIsRightColumnShown(global),
@ -445,36 +445,38 @@ export default memo(withGlobal<OwnProps>(
};
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;