Message: Fix height jump on comments load (#4241)

This commit is contained in:
Alexander Zinchuk 2024-02-06 16:49:19 +01:00
parent af8aa64d8d
commit 1a7fedcb73
5 changed files with 15 additions and 14 deletions

View File

@ -135,8 +135,10 @@ export async function fetchChats({
}
if (resultPinned) {
dispatchThreadInfoUpdates(resultPinned.messages);
updateLocalDb(resultPinned);
}
dispatchThreadInfoUpdates(result.messages);
updateLocalDb(result);
const messages = (resultPinned ? resultPinned.messages : [])
@ -144,8 +146,6 @@ export async function fetchChats({
.map(buildApiMessage)
.filter(Boolean);
dispatchThreadInfoUpdates(result.messages);
const peersByKey = preparePeers(result);
if (resultPinned) {
Object.assign(peersByKey, preparePeers(resultPinned, peersByKey));

View File

@ -51,7 +51,6 @@ import {
buildApiMessage,
buildApiSponsoredMessage,
buildApiThreadInfo,
buildApiThreadInfoFromMessage,
buildLocalForwardedMessage,
buildLocalMessage,
} from '../apiBuilders/messages';
@ -1035,7 +1034,6 @@ export async function fetchDiscussionMessage({
if (!threadId) return undefined;
dispatchThreadInfoUpdates(result.messages);
const threadInfoUpdates = result.messages.map(buildApiThreadInfoFromMessage).filter(Boolean);
const {
unreadCount, maxId, readInboxMaxId, readOutboxMaxId,
@ -1053,7 +1051,6 @@ export async function fetchDiscussionMessage({
lastMessageId: maxId,
chatId: topMessages[0]?.chatId,
firstMessageId: replies.messages[0]?.id,
threadInfoUpdates,
};
}

View File

@ -5,7 +5,7 @@
display: flex;
width: 100%;
align-items: center;
padding: 0.5625rem 0.25rem 0.5625rem 0.625rem;
padding: 0.5rem 0.25rem 0.5rem 0.625rem;
padding-inline-start: 0.625rem;
padding-inline-end: 0.25rem;
background: var(--background-color);
@ -13,7 +13,7 @@
border-bottom-left-radius: var(--border-bottom-left-radius);
font-size: 0.9375rem;
font-weight: 500;
line-height: 2rem;
line-height: 2.125rem;
color: var(--accent-color);
white-space: nowrap;
cursor: var(--custom-cursor, pointer);

View File

@ -172,6 +172,7 @@ export const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 300; // px
export const API_UPDATE_THROTTLE = Math.round((FAST_SMOOTH_MIN_DURATION + FAST_SMOOTH_MAX_DURATION) / 2);
export const API_THROTTLE_RESET_UPDATES = new Set([
'newMessage', 'newScheduledMessage', 'deleteMessages', 'deleteScheduledMessages', 'deleteHistory',
'updateThreadInfos',
]);
export const LOCK_SCREEN_ANIMATION_DURATION_MS = 200;

View File

@ -91,7 +91,6 @@ addActionHandler('sync', (global, actions): ActionReturnType => {
initFolderManager();
loadAllChats({ listType: 'archived', shouldReplace: true });
loadAllChats({ listType: 'saved', shouldReplace: true });
void callApi('fetchCurrentUser');
preloadTopChatMessages();
loadAllStories();
loadAllHiddenStories();
@ -167,6 +166,9 @@ async function loadAndReplaceMessages<T extends GlobalState>(global: T, actions:
.filter(Boolean)
: [];
const resultMessageIds = result.messages.map(({ id }) => id);
const messagesThreadInfos = pick(global.messages.byChatId[currentChatId].threadsById, resultMessageIds);
const isDiscussionStartLoaded = !result.messages.length
|| result.messages.some(({ id }) => id === resultDiscussion?.firstMessageId);
const threadStartMessages = (isDiscussionStartLoaded && resultDiscussion?.topMessages) || [];
@ -194,12 +196,13 @@ async function loadAndReplaceMessages<T extends GlobalState>(global: T, actions:
global = addChatMessagesById(global, currentChatId, byId);
global = updateListedIds(global, currentChatId, activeThreadId, listedIds);
if (resultDiscussion) {
// eslint-disable-next-line @typescript-eslint/no-loop-func
resultDiscussion.threadInfoUpdates.forEach((update) => {
global = updateThreadInfo(global, currentChatId, activeThreadId, update);
});
}
// eslint-disable-next-line @typescript-eslint/no-loop-func
Object.entries(messagesThreadInfos).forEach(([id, thread]) => {
if (!thread?.threadInfo) return;
global = updateThreadInfo(global, currentChatId, id, thread.threadInfo);
});
if (threadInfo && !threadInfo.isCommentsInfo && activeThreadId !== MAIN_THREAD_ID) {
global = updateThreadInfo(global, currentChatId, activeThreadId, {
...pick(threadInfo, ['fromChannelId', 'fromMessageId']),