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 isCustomBackgroundColor = Boolean((customBackground || '').match(/^#[a-f\d]{6,8}$/i));
const currentMessageList = selectCurrentMessageList(global); const currentMessageList = selectCurrentMessageList(global);
const { chats: { listIds } } = 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) { if (!currentMessageList || !listIds.active) {
return { return state;
customBackground,
isBackgroundBlurred,
isCustomBackgroundColor,
};
} }
const { chatId, threadId, type: messageListType } = currentMessageList; const { chatId, threadId, type: messageListType } = currentMessageList;
@ -324,6 +332,7 @@ export default memo(withGlobal(
const isPinnedMessageList = messageListType === 'pinned'; const isPinnedMessageList = messageListType === 'pinned';
return { return {
...state,
chatId, chatId,
threadId, threadId,
messageListType, messageListType,
@ -336,14 +345,6 @@ export default memo(withGlobal(
|| Boolean(pinnedIds && pinnedIds.length) || Boolean(pinnedIds && pinnedIds.length)
|| Boolean(audioChatId && audioMessageId) || 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, [ (setGlobal, actions): DispatchProps => pick(actions, [

View File

@ -429,7 +429,7 @@ export default memo(withGlobal<OwnProps>(
} }
} }
let state: StateProps = { const state: StateProps = {
typingStatus, typingStatus,
isLeftColumnShown, isLeftColumnShown,
isRightColumnShown: selectIsRightColumnShown(global), isRightColumnShown: selectIsRightColumnShown(global),
@ -445,36 +445,38 @@ export default memo(withGlobal<OwnProps>(
}; };
const messagesById = selectChatMessages(global, chatId); const messagesById = selectChatMessages(global, chatId);
if (messageListType === 'thread' && messagesById) { if (messageListType !== 'thread' || !messagesById) {
if (threadId === MAIN_THREAD_ID) { return state;
const pinnedMessageIds = selectPinnedIds(global, chatId); }
if (pinnedMessageIds && pinnedMessageIds.length) { Object.assign(state, { messagesById });
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;
state = { if (threadId !== MAIN_THREAD_ID) {
...state, const pinnedMessageId = selectThreadTopMessageId(global, chatId, threadId);
pinnedMessageIds: pinnedMessageId, const message = pinnedMessageId ? selectChatMessage(global, chatId, pinnedMessageId) : undefined;
messagesById, const sender = message ? selectForwardedSender(global, message) : undefined;
canUnpin: false, const topMessageTitle = sender ? getSenderTitle(sender) : undefined;
topMessageTitle,
}; 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; return state;