Chat List: Fix not loading some chats

This commit is contained in:
Alexander Zinchuk 2021-06-19 16:31:20 +03:00
parent f811726d27
commit 6751813049

View File

@ -75,29 +75,27 @@ export async function fetchChats({
return undefined; return undefined;
} }
updateLocalDb(result);
if (resultPinned) { if (resultPinned) {
updateLocalDb(resultPinned); updateLocalDb(resultPinned);
} }
updateLocalDb(result);
const lastMessagesByChatId = buildCollectionByKey( const lastMessagesByChatId = buildCollectionByKey(
[...result.messages, ...(resultPinned ? resultPinned.messages : [])] (resultPinned ? resultPinned.messages : []).concat(result.messages)
.map(buildApiMessage) .map(buildApiMessage)
.filter<ApiMessage>(Boolean as any), .filter<ApiMessage>(Boolean as any),
'chatId', 'chatId',
); );
const peersByKey: Record<string, GramJs.TypeChat | GramJs.TypeUser> = { const peersByKey: Record<string, GramJs.TypeChat | GramJs.TypeUser> = {
...preparePeers(result),
...(resultPinned && preparePeers(resultPinned)), ...(resultPinned && preparePeers(resultPinned)),
...preparePeers(result),
}; };
const chats: ApiChat[] = []; const chats: ApiChat[] = [];
const draftsById: Record<number, ApiFormattedText> = {}; const draftsById: Record<number, ApiFormattedText> = {};
const replyingToById: Record<number, number> = {}; const replyingToById: Record<number, number> = {};
const dialogs = [ const dialogs = (resultPinned ? resultPinned.dialogs : []).concat(result.dialogs);
...(resultPinned ? resultPinned.dialogs : []),
...result.dialogs,
];
const orderedPinnedIds: number[] = []; const orderedPinnedIds: number[] = [];
@ -131,7 +129,7 @@ export async function fetchChats({
} }
}); });
const users = [...result.users, ...(resultPinned ? resultPinned.users : [])] const users = (resultPinned ? resultPinned.users : []).concat(result.users)
.map(buildApiUser) .map(buildApiUser)
.filter<ApiUser>(Boolean as any); .filter<ApiUser>(Boolean as any);
const chatIds = chats.map((chat) => chat.id); const chatIds = chats.map((chat) => chat.id);