Comments: Fix UI jumping in empty threads (#4088)

This commit is contained in:
Alexander Zinchuk 2023-12-12 12:34:33 +01:00
parent ee60271136
commit 9ef631665f
2 changed files with 5 additions and 1 deletions

View File

@ -186,6 +186,9 @@ addActionHandler('loadViewportMessages', (global, actions, payload): ActionRetur
// Prevent requests with local offsets
if (isLocalMessageId(offsetId)) return;
// Prevent unnecessary requests in threads
if (offsetId === threadId && direction === LoadMoreDirection.Backwards) return;
const isOutlying = Boolean(listedIds && !listedIds.includes(offsetId));
const historyIds = (isOutlying
? selectOutlyingListByMessageId(global, chatId, threadId, offsetId) : listedIds)!;

View File

@ -154,7 +154,8 @@ async function loadAndReplaceMessages<T extends GlobalState>(global: T, actions:
.filter(Boolean)
: [];
const isDiscussionStartLoaded = result.messages.some(({ id }) => id === resultDiscussion?.firstMessageId);
const isDiscussionStartLoaded = !result.messages.length
|| result.messages.some(({ id }) => id === resultDiscussion?.firstMessageId);
const threadStartMessages = (isDiscussionStartLoaded && resultDiscussion?.topMessages) || [];
const allMessages = threadStartMessages.concat(result.messages, localMessages);
const allMessagesWithTopicLastMessages = allMessages.concat(topicLastMessages);