diff --git a/src/global/helpers/messages.ts b/src/global/helpers/messages.ts index 699f0d363..6a2c5407e 100644 --- a/src/global/helpers/messages.ts +++ b/src/global/helpers/messages.ts @@ -194,7 +194,11 @@ export function getSendingState(message: ApiMessage) { } export function isMessageLocal(message: ApiMessage) { - return message.id > LOCAL_MESSAGE_MIN_ID; + return isLocalMessageId(message.id); +} + +export function isLocalMessageId(id: number) { + return id > LOCAL_MESSAGE_MIN_ID; } export function isHistoryClearMessage(message: ApiMessage) { diff --git a/src/global/init.ts b/src/global/init.ts index ce6382e92..a9d61b4cc 100644 --- a/src/global/init.ts +++ b/src/global/init.ts @@ -16,6 +16,7 @@ import { getCurrentTabId, reestablishMasterToSelf } from '../util/establishMulti import { updateTabState } from './reducers/tabs'; import type { ActionReturnType, GlobalState } from './types'; import { getIsMobile } from '../hooks/useAppLayout'; +import { isLocalMessageId } from './helpers'; initCache(); @@ -64,7 +65,7 @@ addActionHandler('init', (global, actions, payload): ActionReturnType => { Object.keys(global.messages.byChatId).forEach((chatId) => { const lastViewportIds = selectThreadParam(global, chatId, MAIN_THREAD_ID, 'lastViewportIds'); // Check if migration from previous version is faulty - if (!lastViewportIds?.every((id) => global.messages.byChatId[chatId]?.byId[id])) { + if (!lastViewportIds?.every((id) => isLocalMessageId(id) || global.messages.byChatId[chatId]?.byId[id])) { global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'lastViewportIds', undefined); return; }