From 065b4ba042192d3d5b7482e71b1f9e0913876d14 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Sat, 31 Oct 2020 20:43:42 +0200 Subject: [PATCH] Fixed changing message ids due to channels state --- src/lib/appManagers/appMessagesIDsManager.ts | 26 +++++++++++++++++++- src/lib/appManagers/appMessagesManager.ts | 6 +++++ src/lib/appManagers/appStateManager.ts | 8 +++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/lib/appManagers/appMessagesIDsManager.ts b/src/lib/appManagers/appMessagesIDsManager.ts index 04b9061c..9809276d 100644 --- a/src/lib/appManagers/appMessagesIDsManager.ts +++ b/src/lib/appManagers/appMessagesIDsManager.ts @@ -1,9 +1,31 @@ +import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; +import appStateManager from "./appStateManager"; + export class AppMessagesIDsManager { public channelLocals: {[channelID: string]: number} = {}; public channelsByLocals: {[localStart: string]: number} = {}; public channelCurLocal = 0; public fullMsgIDModulus = 4294967296; + constructor() { + appStateManager.getState().then(state => { + const cached = state.messagesIDsLocals; + if(cached) { + this.channelLocals = cached.channelLocals; + this.channelsByLocals = cached.channelsByLocals; + this.channelCurLocal = cached.channelCurLocal; + } + }); + + appStateManager.addListener('save', () => { + appStateManager.pushToState('messagesIDsLocals', { + channelLocals: this.channelLocals, + channelsByLocals: this.channelsByLocals, + channelCurLocal: this.channelCurLocal + }); + }); + } + public getFullMessageID(msgID: number, channelID: number): number { if(!channelID || msgID <= 0) { return msgID; @@ -58,4 +80,6 @@ export class AppMessagesIDsManager { } } -export default new AppMessagesIDsManager(); +const appMessagesIDsManager = new AppMessagesIDsManager(); +MOUNT_CLASS_TO.appMessagesIDsManager = appMessagesIDsManager; +export default appMessagesIDsManager; diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 16fa274c..b74131cd 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -654,6 +654,12 @@ export class AppMessagesManager { if(state.dialogs) { state.dialogs.forEachReverse(dialog => { this.saveConversation(dialog); + + // ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись + const message = this.getMessage(dialog.top_message); + if(message.deleted) { + this.reloadConversation(dialog.peerID); + } }); } }); diff --git a/src/lib/appManagers/appStateManager.ts b/src/lib/appManagers/appStateManager.ts index 761b9fb4..74f17110 100644 --- a/src/lib/appManagers/appStateManager.ts +++ b/src/lib/appManagers/appStateManager.ts @@ -8,6 +8,7 @@ import { logger } from '../logger'; import type { AppUsersManager } from './appUsersManager'; import type { AppChatsManager } from './appChatsManager'; import type { AuthState } from '../../types'; +import type { AppMessagesIDsManager } from './appMessagesIDsManager'; const REFRESH_EVERY = 24 * 60 * 60 * 1000; // 1 day const STATE_VERSION = App.version; @@ -29,7 +30,12 @@ type State = Partial<{ recentSearch: number[], stickerSets: AppStickersManager['stickerSets'], version: typeof STATE_VERSION, - authState: AuthState + authState: AuthState, + messagesIDsLocals: { + channelLocals: AppMessagesIDsManager['channelLocals'], + channelsByLocals: AppMessagesIDsManager['channelsByLocals'], + channelCurLocal: AppMessagesIDsManager['channelCurLocal'], + } }>; const REFRESH_KEYS = ['dialogs', 'allDialogsLoaded', 'messages', 'contactsList', 'stateCreatedTime',