From 9ef631665fc94bae66099f4327004d1cddd537e3 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 12 Dec 2023 12:34:33 +0100 Subject: [PATCH] Comments: Fix UI jumping in empty threads (#4088) --- src/global/actions/api/messages.ts | 3 +++ src/global/actions/api/sync.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index de5132fdc..18eb3ebe0 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -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)!; diff --git a/src/global/actions/api/sync.ts b/src/global/actions/api/sync.ts index 0fb962b6b..83de53039 100644 --- a/src/global/actions/api/sync.ts +++ b/src/global/actions/api/sync.ts @@ -154,7 +154,8 @@ async function loadAndReplaceMessages(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);