[Refactoring] Multitabs: Fix creating redundant message list records (#2604)

This commit is contained in:
Alexander Zinchuk 2023-02-17 02:31:57 +01:00
parent 99dc944de6
commit 511668b72a
2 changed files with 24 additions and 6 deletions

View File

@ -55,7 +55,7 @@ import {
selectChatFolder, selectSupportChat, selectChatByUsername,
selectCurrentMessageList, selectThreadInfo, selectCurrentChat, selectLastServiceNotification,
selectVisibleUsers, selectUserByPhoneNumber, selectDraft, selectThreadTopMessageId,
selectTabState,
selectTabState, selectThread,
} from '../../selectors';
import { buildCollectionByKey, omit } from '../../../util/iteratees';
import { debounce, pause, throttle } from '../../../util/schedulers';
@ -1898,17 +1898,27 @@ async function loadChats<T extends GlobalState>(
const idsToUpdateDraft = isFullDraftSync ? result.chatIds : Object.keys(result.draftsById);
idsToUpdateDraft.forEach((chatId) => {
const draft = result.draftsById[chatId];
const thread = selectThread(global, chatId, MAIN_THREAD_ID);
if (!draft && !thread) return;
if (!selectDraft(global, chatId, MAIN_THREAD_ID)?.isLocal) {
global = replaceThreadParam(
global, chatId, MAIN_THREAD_ID, 'draft', result.draftsById[chatId],
global, chatId, MAIN_THREAD_ID, 'draft', draft,
);
}
});
const idsToUpdateReplyingToId = isFullDraftSync ? result.chatIds : Object.keys(result.replyingToById);
idsToUpdateReplyingToId.forEach((chatId) => {
const replyingToById = result.replyingToById[chatId];
const thread = selectThread(global, chatId, MAIN_THREAD_ID);
if (!replyingToById && !thread) return;
global = replaceThreadParam(
global, chatId, MAIN_THREAD_ID, 'replyingToId', result.replyingToById[chatId],
global, chatId, MAIN_THREAD_ID, 'replyingToId', replyingToById,
);
});

View File

@ -95,11 +95,19 @@ export function selectTabThreadParam<T extends GlobalState, K extends keyof TabT
return selectTabState(global, tabId).tabThreads[chatId]?.[threadId]?.[key];
}
export function selectThreadParam<K extends keyof Thread>(
global: GlobalState,
export function selectThreadParam<T extends GlobalState, K extends keyof Thread>(
global: T,
chatId: string,
threadId: number,
key: K,
) {
return selectThread(global, chatId, threadId)?.[key];
}
export function selectThread<T extends GlobalState>(
global: T,
chatId: string,
threadId: number,
) {
const messageInfo = global.messages.byChatId[chatId];
if (!messageInfo) {
@ -111,7 +119,7 @@ export function selectThreadParam<K extends keyof Thread>(
return undefined;
}
return thread[key];
return thread;
}
export function selectListedIds<T extends GlobalState>(global: T, chatId: string, threadId: number) {