Chat List: Fix disappearing entries (#5334)

This commit is contained in:
zubiden 2024-12-20 11:37:31 +01:00 committed by Alexander Zinchuk
parent f9a05956b7
commit 55170dc047
4 changed files with 10 additions and 9 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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();
}

View File

@ -86,7 +86,7 @@ export function updateChatsLastMessageId<T extends GlobalState>(
};
}
export function updateChatListIds<T extends GlobalState>(
export function addChatListIds<T extends GlobalState>(
global: T, type: ChatListType, idsUpdate: string[],
): T {
const { [type]: listIds } = global.chats.listIds;