Fix updates
This commit is contained in:
parent
48e8ddd370
commit
54cc536a85
@ -1,5 +1,6 @@
|
||||
//import apiManager from '../mtproto/apiManager';
|
||||
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
|
||||
import { copy } from '../../helpers/object';
|
||||
import { logger, LogLevels } from '../logger';
|
||||
import apiManager from '../mtproto/mtprotoworker';
|
||||
import rootScope from '../rootScope';
|
||||
@ -41,18 +42,6 @@ export class ApiUpdatesManager {
|
||||
private log = logger('UPDATES', LogLevels.error | LogLevels.log | LogLevels.warn | LogLevels.debug);
|
||||
private debug = DEBUG;
|
||||
|
||||
constructor() {
|
||||
// * false for test purposes
|
||||
/* false && */appStateManager.addListener('save', async() => {
|
||||
const us = this.updatesState;
|
||||
appStateManager.pushToState('updates', {
|
||||
seq: us.seq,
|
||||
pts: us.pts,
|
||||
date: us.date
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public popPendingSeqUpdate() {
|
||||
const state = this.updatesState;
|
||||
const nextSeq = state.seq + 1;
|
||||
@ -579,15 +568,17 @@ export class ApiUpdatesManager {
|
||||
|
||||
//return;
|
||||
|
||||
this.log('attach');
|
||||
|
||||
this.attached = true;
|
||||
|
||||
appStateManager.getState().then(_state => {
|
||||
const state = _state.updates;
|
||||
|
||||
apiManager.setUpdatesProcessor(this.processUpdateMessage);
|
||||
|
||||
//rootScope.broadcast('state_synchronizing');
|
||||
if(!state || !state.pts || !state.date || !state.seq) {
|
||||
this.log('will get new state');
|
||||
|
||||
this.updatesState.syncLoading = new Promise((resolve) => {
|
||||
apiManager.invokeApi('updates.getState', {}, {noErrorBox: true}).then((stateResult) => {
|
||||
this.updatesState.seq = stateResult.seq;
|
||||
@ -614,12 +605,28 @@ export class ApiUpdatesManager {
|
||||
|
||||
Object.assign(this.updatesState, state);
|
||||
|
||||
this.log('will get difference', copy(state));
|
||||
|
||||
this.getDifference(true)/* .finally(() => {
|
||||
if(this.updatesState.syncLoading) {
|
||||
rootScope.broadcast('state_synchronizing');
|
||||
}
|
||||
}) */;
|
||||
}
|
||||
|
||||
apiManager.setUpdatesProcessor(this.processUpdateMessage);
|
||||
|
||||
this.updatesState.syncLoading.then(() => {
|
||||
// * false for test purposes
|
||||
/* false && */appStateManager.addListener('save', async() => {
|
||||
const us = this.updatesState;
|
||||
appStateManager.pushToState('updates', {
|
||||
seq: us.seq,
|
||||
pts: us.pts,
|
||||
date: us.date
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ export class AppDraftsManager {
|
||||
constructor() {
|
||||
appStateManager.getState().then(state => {
|
||||
this.drafts = state.drafts;
|
||||
});
|
||||
|
||||
appStateManager.addListener('save', async() => {
|
||||
appStateManager.pushToState('drafts', this.drafts);
|
||||
});
|
||||
});
|
||||
|
||||
rootScope.on('apiUpdate', (update) => {
|
||||
if(update._ !== 'updateDraftMessage') {
|
||||
|
@ -237,7 +237,64 @@ export class AppMessagesManager {
|
||||
}
|
||||
});
|
||||
|
||||
appStateManager.addListener('save', () => {
|
||||
appStateManager.getState().then(state => {
|
||||
if(state.maxSeenMsgId) {
|
||||
this.maxSeenId = state.maxSeenMsgId;
|
||||
}
|
||||
|
||||
const messages = state.messages;
|
||||
if(messages) {
|
||||
/* let tempId = this.tempId;
|
||||
|
||||
for(let message of messages) {
|
||||
if(message.id < tempId) {
|
||||
tempId = message.id;
|
||||
}
|
||||
}
|
||||
|
||||
if(tempId !== this.tempId) {
|
||||
this.log('Set tempId to:', tempId);
|
||||
this.tempId = tempId;
|
||||
} */
|
||||
|
||||
this.saveMessages(messages);
|
||||
}
|
||||
|
||||
if(!state.dialogs || !Object.keys(state.dialogs).length) {
|
||||
state.allDialogsLoaded = {};
|
||||
}
|
||||
|
||||
if(state.allDialogsLoaded) {
|
||||
this.dialogsStorage.allDialogsLoaded = state.allDialogsLoaded;
|
||||
}
|
||||
|
||||
if(state.filters) {
|
||||
for(const filterId in state.filters) {
|
||||
this.filtersStorage.saveDialogFilter(state.filters[filterId], false);
|
||||
}
|
||||
}
|
||||
|
||||
if(state.dialogs) {
|
||||
state.dialogs.forEachReverse(dialog => {
|
||||
dialog.top_message = this.getServerMessageId(dialog.top_message); // * fix outgoing message to avoid copying dialog
|
||||
|
||||
this.saveConversation(dialog);
|
||||
|
||||
// ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись
|
||||
const message = this.getMessageByPeer(dialog.peerId, dialog.top_message);
|
||||
if(message.deleted) {
|
||||
this.reloadConversation(dialog.peerId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
appStateManager.addListener('save', this.saveState);
|
||||
});
|
||||
|
||||
appNotificationsManager.start();
|
||||
}
|
||||
|
||||
private saveState = () => {
|
||||
const messages: any[] = [];
|
||||
const dialogs: Dialog[] = [];
|
||||
const items: any[] = [];
|
||||
@ -297,62 +354,7 @@ export class AppMessagesManager {
|
||||
appStateManager.pushToState('allDialogsLoaded', this.dialogsStorage.allDialogsLoaded);
|
||||
appStateManager.pushToState('maxSeenMsgId', this.maxSeenId);
|
||||
});
|
||||
});
|
||||
|
||||
appStateManager.getState().then(state => {
|
||||
if(state.maxSeenMsgId) {
|
||||
this.maxSeenId = state.maxSeenMsgId;
|
||||
}
|
||||
|
||||
const messages = state.messages;
|
||||
if(messages) {
|
||||
/* let tempId = this.tempId;
|
||||
|
||||
for(let message of messages) {
|
||||
if(message.id < tempId) {
|
||||
tempId = message.id;
|
||||
}
|
||||
}
|
||||
|
||||
if(tempId !== this.tempId) {
|
||||
this.log('Set tempId to:', tempId);
|
||||
this.tempId = tempId;
|
||||
} */
|
||||
|
||||
this.saveMessages(messages);
|
||||
}
|
||||
|
||||
if(!state.dialogs || !Object.keys(state.dialogs).length) {
|
||||
state.allDialogsLoaded = {};
|
||||
}
|
||||
|
||||
if(state.allDialogsLoaded) {
|
||||
this.dialogsStorage.allDialogsLoaded = state.allDialogsLoaded;
|
||||
}
|
||||
|
||||
if(state.filters) {
|
||||
for(const filterId in state.filters) {
|
||||
this.filtersStorage.saveDialogFilter(state.filters[filterId], false);
|
||||
}
|
||||
}
|
||||
|
||||
if(state.dialogs) {
|
||||
state.dialogs.forEachReverse(dialog => {
|
||||
dialog.top_message = this.getServerMessageId(dialog.top_message); // * fix outgoing message to avoid copying dialog
|
||||
|
||||
this.saveConversation(dialog);
|
||||
|
||||
// ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись
|
||||
const message = this.getMessageByPeer(dialog.peerId, dialog.top_message);
|
||||
if(message.deleted) {
|
||||
this.reloadConversation(dialog.peerId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
appNotificationsManager.start();
|
||||
}
|
||||
};
|
||||
|
||||
public getInputEntities(entities: MessageEntity[]) {
|
||||
var sendEntites = copy(entities);
|
||||
|
@ -196,7 +196,7 @@ export class AppStateManager extends EventListenerBase<{
|
||||
rootScope.settings = this.state.settings;
|
||||
|
||||
if(DEBUG) {
|
||||
this.log('state res', state);
|
||||
this.log('state res', state, copy(state));
|
||||
}
|
||||
|
||||
//return resolve();
|
||||
|
@ -90,15 +90,6 @@ export class AppUsersManager {
|
||||
}
|
||||
});
|
||||
|
||||
appStateManager.addListener('save', async() => {
|
||||
const contactsList = [...this.contactsList];
|
||||
for(const userId of contactsList) {
|
||||
appStateManager.setPeer(userId, this.getUser(userId));
|
||||
}
|
||||
|
||||
appStateManager.pushToState('contactsList', contactsList);
|
||||
});
|
||||
|
||||
appStateManager.getState().then((state) => {
|
||||
this.users = state.users;
|
||||
|
||||
@ -112,6 +103,15 @@ export class AppUsersManager {
|
||||
this.contactsFillPromise = Promise.resolve(this.contactsList);
|
||||
}
|
||||
}
|
||||
|
||||
appStateManager.addListener('save', async() => {
|
||||
const contactsList = [...this.contactsList];
|
||||
for(const userId of contactsList) {
|
||||
appStateManager.setPeer(userId, this.getUser(userId));
|
||||
}
|
||||
|
||||
appStateManager.pushToState('contactsList', contactsList);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user