From df362bb78f7842e5134bc9608819d541d5af900f Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 16 Jan 2023 14:16:37 +0100 Subject: [PATCH] Chat List: Fix missing some chats --- src/api/gramjs/methods/chats.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index 4078ec653..d5bb155f5 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -119,10 +119,12 @@ export async function fetchChats({ .filter(Boolean), 'chatId', ); - const peersByKey: Record = { - ...(resultPinned && preparePeers(resultPinned)), - ...preparePeers(result), - }; + + const peersByKey = preparePeers(result); + if (resultPinned) { + Object.assign(peersByKey, preparePeers(resultPinned, peersByKey)); + } + const chats: ApiChat[] = []; const draftsById: Record = {}; const replyingToById: Record = {}; @@ -155,6 +157,7 @@ export async function fetchChats({ } chat.isListed = true; + chats.push(chat); if (withPinned && dialog.pinned) { @@ -1260,15 +1263,28 @@ export function toggleJoinRequest(chat: ApiChat, isEnabled: boolean) { function preparePeers( result: GramJs.messages.Dialogs | GramJs.messages.DialogsSlice | GramJs.messages.PeerDialogs, + currentStore?: Record, ) { const store: Record = {}; result.chats?.forEach((chat) => { - store[`chat${chat.id}`] = chat; + const key = `chat${chat.id}`; + + if (currentStore?.[key] && 'min' in chat && chat.min) { + return; + } + + store[key] = chat; }); result.users?.forEach((user) => { - store[`user${user.id}`] = user; + const key = `user${user.id}`; + + if (currentStore?.[key] && 'min' in user && user.min) { + return; + } + + store[key] = user; }); return store;