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;