Fixed changing message ids due to channels state
This commit is contained in:
parent
beefa0a01d
commit
065b4ba042
@ -1,9 +1,31 @@
|
|||||||
|
import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
|
||||||
|
import appStateManager from "./appStateManager";
|
||||||
|
|
||||||
export class AppMessagesIDsManager {
|
export class AppMessagesIDsManager {
|
||||||
public channelLocals: {[channelID: string]: number} = {};
|
public channelLocals: {[channelID: string]: number} = {};
|
||||||
public channelsByLocals: {[localStart: string]: number} = {};
|
public channelsByLocals: {[localStart: string]: number} = {};
|
||||||
public channelCurLocal = 0;
|
public channelCurLocal = 0;
|
||||||
public fullMsgIDModulus = 4294967296;
|
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 {
|
public getFullMessageID(msgID: number, channelID: number): number {
|
||||||
if(!channelID || msgID <= 0) {
|
if(!channelID || msgID <= 0) {
|
||||||
return msgID;
|
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;
|
||||||
|
@ -654,6 +654,12 @@ export class AppMessagesManager {
|
|||||||
if(state.dialogs) {
|
if(state.dialogs) {
|
||||||
state.dialogs.forEachReverse(dialog => {
|
state.dialogs.forEachReverse(dialog => {
|
||||||
this.saveConversation(dialog);
|
this.saveConversation(dialog);
|
||||||
|
|
||||||
|
// ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись
|
||||||
|
const message = this.getMessage(dialog.top_message);
|
||||||
|
if(message.deleted) {
|
||||||
|
this.reloadConversation(dialog.peerID);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ import { logger } from '../logger';
|
|||||||
import type { AppUsersManager } from './appUsersManager';
|
import type { AppUsersManager } from './appUsersManager';
|
||||||
import type { AppChatsManager } from './appChatsManager';
|
import type { AppChatsManager } from './appChatsManager';
|
||||||
import type { AuthState } from '../../types';
|
import type { AuthState } from '../../types';
|
||||||
|
import type { AppMessagesIDsManager } from './appMessagesIDsManager';
|
||||||
|
|
||||||
const REFRESH_EVERY = 24 * 60 * 60 * 1000; // 1 day
|
const REFRESH_EVERY = 24 * 60 * 60 * 1000; // 1 day
|
||||||
const STATE_VERSION = App.version;
|
const STATE_VERSION = App.version;
|
||||||
@ -29,7 +30,12 @@ type State = Partial<{
|
|||||||
recentSearch: number[],
|
recentSearch: number[],
|
||||||
stickerSets: AppStickersManager['stickerSets'],
|
stickerSets: AppStickersManager['stickerSets'],
|
||||||
version: typeof STATE_VERSION,
|
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',
|
const REFRESH_KEYS = ['dialogs', 'allDialogsLoaded', 'messages', 'contactsList', 'stateCreatedTime',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user