Multitabs: Fix disappearing messages on tab reload (#2484)

This commit is contained in:
Alexander Zinchuk 2023-02-03 03:22:16 +01:00
parent 573583ce67
commit 4353276c66
2 changed files with 7 additions and 2 deletions

View File

@ -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) {

View File

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