From dcdad5152e983856269c2f6368d44ae843a323a8 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:53:20 +0200 Subject: [PATCH] Chat List: Potential fix for stuck entries (#5048) --- src/global/actions/api/chats.ts | 15 +++++++++------ src/global/actions/apiUpdaters/messages.ts | 9 +++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index adce9f093..1fcea744a 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -559,8 +559,8 @@ addActionHandler('loadFullChat', (global, actions, payload): ActionReturnType => addActionHandler('loadTopChats', (): ActionReturnType => { runThrottledForLoadTopChats(() => { - loadChats('active'); - loadChats('archived'); + loadChats('active', undefined, true); + loadChats('archived', undefined, true); }); }); @@ -2732,12 +2732,13 @@ addActionHandler('requestCollectibleInfo', async (global, actions, payload): Pro async function loadChats( listType: ChatListType, isFullDraftSync?: boolean, + shouldIgnorePagination?: boolean, ) { // eslint-disable-next-line eslint-multitab-tt/no-immediate-global let global = getGlobal(); let lastLocalServiceMessageId = selectLastServiceNotification(global)?.id; - const params = selectChatListLoadingParameters(global, listType); + const params = !shouldIgnorePagination ? selectChatListLoadingParameters(global, listType) : {}; const offsetPeer = params.nextOffsetPeerId ? selectPeer(global, params.nextOffsetPeerId) : undefined; const offsetDate = params.nextOffsetDate; const offsetId = params.nextOffsetId; @@ -2785,9 +2786,11 @@ async function loadChats( global = addMessages(global, result.messages); global = updateChatsLastMessageId(global, result.lastMessageByChatId, listType); - global = replaceChatListLoadingParameters( - global, listType, result.nextOffsetId, result.nextOffsetPeerId, result.nextOffsetDate, - ); + if (!shouldIgnorePagination) { + global = replaceChatListLoadingParameters( + global, listType, result.nextOffsetId, result.nextOffsetPeerId, result.nextOffsetDate, + ); + } const idsToUpdateDraft = isFullDraftSync ? result.chatIds : Object.keys(result.draftsById); idsToUpdateDraft.forEach((chatId) => { diff --git a/src/global/actions/apiUpdaters/messages.ts b/src/global/actions/apiUpdaters/messages.ts index 89e5da391..25d0a156c 100644 --- a/src/global/actions/apiUpdaters/messages.ts +++ b/src/global/actions/apiUpdaters/messages.ts @@ -157,11 +157,11 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { setGlobal(global); // Reload dialogs if chat is not present in the list - if (!selectIsChatListed(global, chatId)) { + if (!isLocal && !selectIsChatListed(global, chatId)) { actions.loadTopChats(); } - if (selectIsChatWithSelf(global, chatId) && !isLocal) { + if (!isLocal && selectIsChatWithSelf(global, chatId)) { const savedDialogId = selectSavedDialogIdFromMessage(global, newMessage); if (savedDialogId && !selectIsChatListed(global, savedDialogId, 'saved')) { actions.requestSavedDialogUpdate({ chatId: savedDialogId }); @@ -359,6 +359,11 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { lastReadInboxMessageId: message.id, }); + // Reload dialogs if chat is not present in the list + if (!selectIsChatListed(global, chatId)) { + actions.loadTopChats(); + } + if (selectIsChatWithSelf(global, chatId)) { const savedDialogId = selectSavedDialogIdFromMessage(global, newMessage); if (savedDialogId && !selectIsChatListed(global, savedDialogId, 'saved')) {