diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index d31116b54..36cd15572 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -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)); diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index 184b3b098..cf8d40372 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -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, }; } diff --git a/src/components/middle/message/CommentButton.scss b/src/components/middle/message/CommentButton.scss index 5e3153e85..6f772d561 100644 --- a/src/components/middle/message/CommentButton.scss +++ b/src/components/middle/message/CommentButton.scss @@ -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); diff --git a/src/config.ts b/src/config.ts index ddc9135bb..5bffd0a44 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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; diff --git a/src/global/actions/api/sync.ts b/src/global/actions/api/sync.ts index fd6a43345..652463f29 100644 --- a/src/global/actions/api/sync.ts +++ b/src/global/actions/api/sync.ts @@ -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(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(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']),