diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 9b574cd0f..d791188e2 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -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( 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, ); }); diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index bd2276959..a6b66a41d 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -95,11 +95,19 @@ export function selectTabThreadParam( - global: GlobalState, +export function selectThreadParam( + global: T, chatId: string, threadId: number, key: K, +) { + return selectThread(global, chatId, threadId)?.[key]; +} + +export function selectThread( + global: T, + chatId: string, + threadId: number, ) { const messageInfo = global.messages.byChatId[chatId]; if (!messageInfo) { @@ -111,7 +119,7 @@ export function selectThreadParam( return undefined; } - return thread[key]; + return thread; } export function selectListedIds(global: T, chatId: string, threadId: number) {