Fix updates
This commit is contained in:
parent
48e8ddd370
commit
54cc536a85
@ -1,5 +1,6 @@
|
|||||||
//import apiManager from '../mtproto/apiManager';
|
//import apiManager from '../mtproto/apiManager';
|
||||||
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
|
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
|
||||||
|
import { copy } from '../../helpers/object';
|
||||||
import { logger, LogLevels } from '../logger';
|
import { logger, LogLevels } from '../logger';
|
||||||
import apiManager from '../mtproto/mtprotoworker';
|
import apiManager from '../mtproto/mtprotoworker';
|
||||||
import rootScope from '../rootScope';
|
import rootScope from '../rootScope';
|
||||||
@ -41,18 +42,6 @@ export class ApiUpdatesManager {
|
|||||||
private log = logger('UPDATES', LogLevels.error | LogLevels.log | LogLevels.warn | LogLevels.debug);
|
private log = logger('UPDATES', LogLevels.error | LogLevels.log | LogLevels.warn | LogLevels.debug);
|
||||||
private debug = 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() {
|
public popPendingSeqUpdate() {
|
||||||
const state = this.updatesState;
|
const state = this.updatesState;
|
||||||
const nextSeq = state.seq + 1;
|
const nextSeq = state.seq + 1;
|
||||||
@ -579,15 +568,17 @@ export class ApiUpdatesManager {
|
|||||||
|
|
||||||
//return;
|
//return;
|
||||||
|
|
||||||
|
this.log('attach');
|
||||||
|
|
||||||
this.attached = true;
|
this.attached = true;
|
||||||
|
|
||||||
appStateManager.getState().then(_state => {
|
appStateManager.getState().then(_state => {
|
||||||
const state = _state.updates;
|
const state = _state.updates;
|
||||||
|
|
||||||
apiManager.setUpdatesProcessor(this.processUpdateMessage);
|
|
||||||
|
|
||||||
//rootScope.broadcast('state_synchronizing');
|
//rootScope.broadcast('state_synchronizing');
|
||||||
if(!state || !state.pts || !state.date || !state.seq) {
|
if(!state || !state.pts || !state.date || !state.seq) {
|
||||||
|
this.log('will get new state');
|
||||||
|
|
||||||
this.updatesState.syncLoading = new Promise((resolve) => {
|
this.updatesState.syncLoading = new Promise((resolve) => {
|
||||||
apiManager.invokeApi('updates.getState', {}, {noErrorBox: true}).then((stateResult) => {
|
apiManager.invokeApi('updates.getState', {}, {noErrorBox: true}).then((stateResult) => {
|
||||||
this.updatesState.seq = stateResult.seq;
|
this.updatesState.seq = stateResult.seq;
|
||||||
@ -614,12 +605,28 @@ export class ApiUpdatesManager {
|
|||||||
|
|
||||||
Object.assign(this.updatesState, state);
|
Object.assign(this.updatesState, state);
|
||||||
|
|
||||||
|
this.log('will get difference', copy(state));
|
||||||
|
|
||||||
this.getDifference(true)/* .finally(() => {
|
this.getDifference(true)/* .finally(() => {
|
||||||
if(this.updatesState.syncLoading) {
|
if(this.updatesState.syncLoading) {
|
||||||
rootScope.broadcast('state_synchronizing');
|
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() {
|
constructor() {
|
||||||
appStateManager.getState().then(state => {
|
appStateManager.getState().then(state => {
|
||||||
this.drafts = state.drafts;
|
this.drafts = state.drafts;
|
||||||
});
|
|
||||||
|
|
||||||
appStateManager.addListener('save', async() => {
|
appStateManager.addListener('save', async() => {
|
||||||
appStateManager.pushToState('drafts', this.drafts);
|
appStateManager.pushToState('drafts', this.drafts);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
rootScope.on('apiUpdate', (update) => {
|
rootScope.on('apiUpdate', (update) => {
|
||||||
if(update._ !== 'updateDraftMessage') {
|
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 messages: any[] = [];
|
||||||
const dialogs: Dialog[] = [];
|
const dialogs: Dialog[] = [];
|
||||||
const items: any[] = [];
|
const items: any[] = [];
|
||||||
@ -297,62 +354,7 @@ export class AppMessagesManager {
|
|||||||
appStateManager.pushToState('allDialogsLoaded', this.dialogsStorage.allDialogsLoaded);
|
appStateManager.pushToState('allDialogsLoaded', this.dialogsStorage.allDialogsLoaded);
|
||||||
appStateManager.pushToState('maxSeenMsgId', this.maxSeenId);
|
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[]) {
|
public getInputEntities(entities: MessageEntity[]) {
|
||||||
var sendEntites = copy(entities);
|
var sendEntites = copy(entities);
|
||||||
|
@ -196,7 +196,7 @@ export class AppStateManager extends EventListenerBase<{
|
|||||||
rootScope.settings = this.state.settings;
|
rootScope.settings = this.state.settings;
|
||||||
|
|
||||||
if(DEBUG) {
|
if(DEBUG) {
|
||||||
this.log('state res', state);
|
this.log('state res', state, copy(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
//return resolve();
|
//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) => {
|
appStateManager.getState().then((state) => {
|
||||||
this.users = state.users;
|
this.users = state.users;
|
||||||
|
|
||||||
@ -112,6 +103,15 @@ export class AppUsersManager {
|
|||||||
this.contactsFillPromise = Promise.resolve(this.contactsList);
|
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