From 55170dc0472339ff2e15cf0ba63b93613252c498 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:37:31 +0100 Subject: [PATCH] Chat List: Fix disappearing entries (#5334) --- src/global/actions/api/chats.ts | 8 ++++---- src/global/actions/apiUpdaters/chats.ts | 4 ++-- src/global/actions/apiUpdaters/messages.ts | 5 +++-- src/global/reducers/chats.ts | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index b8a671a65..efb63a124 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -55,6 +55,7 @@ import { addActionHandler, getGlobal, setGlobal, } from '../../index'; import { + addChatListIds, addChatMembers, addChats, addMessages, @@ -76,7 +77,6 @@ import { updateChat, updateChatFullInfo, updateChatLastMessageId, - updateChatListIds, updateChatListSecondaryInfo, updateChats, updateChatsLastMessageId, @@ -600,7 +600,7 @@ addActionHandler('requestSavedDialogUpdate', async (global, actions, payload): P if (result.messages.length) { global = updateChatLastMessageId(global, chatId, result.messages[0].id, 'saved'); - global = updateChatListIds(global, 'saved', [chatId]); + global = addChatListIds(global, 'saved', [chatId]); setGlobal(global); } else { @@ -2748,7 +2748,7 @@ async function loadChats( const offsetDate = params.nextOffsetDate; const offsetId = params.nextOffsetId; - const isFirstBatch = !offsetPeer && !offsetDate && !offsetId; + const isFirstBatch = !shouldIgnorePagination && !offsetPeer && !offsetDate && !offsetId; const result = listType === 'saved' ? await callApi('fetchSavedChats', { limit: CHAT_LIST_LOAD_SLICE, @@ -2783,7 +2783,7 @@ async function loadChats( global = replaceChatListIds(global, listType, chatIds); global = replaceUserStatuses(global, result.userStatusesById); } else { - global = updateChatListIds(global, listType, chatIds); + global = addChatListIds(global, listType, chatIds); global = addUserStatuses(global, result.userStatusesById); } diff --git a/src/global/actions/apiUpdaters/chats.ts b/src/global/actions/apiUpdaters/chats.ts index 355c8de8d..0e6175ecf 100644 --- a/src/global/actions/apiUpdaters/chats.ts +++ b/src/global/actions/apiUpdaters/chats.ts @@ -11,6 +11,7 @@ import { addActionHandler, getGlobal, setGlobal, } from '../../index'; import { + addChatListIds, addUnreadMentions, deleteChatMessages, deletePeerPhoto, @@ -21,7 +22,6 @@ import { replaceThreadParam, updateChat, updateChatFullInfo, - updateChatListIds, updateChatListType, updatePeerStoriesHidden, updateTopic, @@ -114,7 +114,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { } global = getGlobal(); - global = updateChatListIds(global, listType, [update.id]); + global = addChatListIds(global, listType, [update.id]); setGlobal(global); return undefined; diff --git a/src/global/actions/apiUpdaters/messages.ts b/src/global/actions/apiUpdaters/messages.ts index a2f3c15ec..bf2df6e20 100644 --- a/src/global/actions/apiUpdaters/messages.ts +++ b/src/global/actions/apiUpdaters/messages.ts @@ -166,7 +166,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { setGlobal(global); // Reload dialogs if chat is not present in the list - if (!isLocal && !selectIsChatListed(global, chatId)) { + if (!isLocal && chat && !chat.isNotJoined && !selectIsChatListed(global, chatId)) { actions.loadTopChats(); } @@ -444,8 +444,9 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { lastReadInboxMessageId: message.id, }); + const chat = selectChat(global, chatId); // Reload dialogs if chat is not present in the list - if (!selectIsChatListed(global, chatId)) { + if (chat && !chat.isNotJoined && !selectIsChatListed(global, chatId)) { actions.loadTopChats(); } diff --git a/src/global/reducers/chats.ts b/src/global/reducers/chats.ts index d05d0d632..52c99a093 100644 --- a/src/global/reducers/chats.ts +++ b/src/global/reducers/chats.ts @@ -86,7 +86,7 @@ export function updateChatsLastMessageId( }; } -export function updateChatListIds( +export function addChatListIds( global: T, type: ChatListType, idsUpdate: string[], ): T { const { [type]: listIds } = global.chats.listIds;