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,10 +21,10 @@ export class AppDraftsManager {
|
||||
constructor() {
|
||||
appStateManager.getState().then(state => {
|
||||
this.drafts = state.drafts;
|
||||
});
|
||||
|
||||
appStateManager.addListener('save', async() => {
|
||||
appStateManager.pushToState('drafts', this.drafts);
|
||||
appStateManager.addListener('save', async() => {
|
||||
appStateManager.pushToState('drafts', this.drafts);
|
||||
});
|
||||
});
|
||||
|
||||
rootScope.on('apiUpdate', (update) => {
|
||||
|
@ -237,68 +237,6 @@ export class AppMessagesManager {
|
||||
}
|
||||
});
|
||||
|
||||
appStateManager.addListener('save', () => {
|
||||
const messages: any[] = [];
|
||||
const dialogs: Dialog[] = [];
|
||||
const items: any[] = [];
|
||||
|
||||
const processDialog = (dialog: MTDialog.dialog) => {
|
||||
const historyStorage = this.getHistoryStorage(dialog.peerId);
|
||||
const history = [].concat(historyStorage.history.slice);
|
||||
//dialog = copy(dialog);
|
||||
let removeUnread = 0;
|
||||
for(const mid of history) {
|
||||
const message = this.getMessageByPeer(dialog.peerId, mid);
|
||||
if(/* message._ !== 'messageEmpty' && */!message.pFlags.is_outgoing) {
|
||||
messages.push(message);
|
||||
|
||||
if(message.fromId !== dialog.peerId) {
|
||||
appStateManager.setPeer(message.fromId, appPeersManager.getPeer(message.fromId));
|
||||
}
|
||||
|
||||
/* dialog.top_message = message.mid;
|
||||
this.dialogsStorage.generateIndexForDialog(dialog, false, message); */
|
||||
|
||||
break;
|
||||
} else if(message.pFlags && message.pFlags.unread) {
|
||||
++removeUnread;
|
||||
}
|
||||
}
|
||||
|
||||
if(removeUnread && dialog.unread_count) dialog.unread_count -= removeUnread;
|
||||
|
||||
if(dialog.peerId < 0 && dialog.pts) {
|
||||
const newPts = apiUpdatesManager.channelStates[-dialog.peerId].pts;
|
||||
dialog.pts = newPts;
|
||||
}
|
||||
|
||||
dialog.unread_count = Math.max(0, dialog.unread_count);
|
||||
dialogs.push(dialog);
|
||||
|
||||
appStateManager.setPeer(dialog.peerId, appPeersManager.getPeer(dialog.peerId));
|
||||
};
|
||||
|
||||
for(const folderId in this.dialogsStorage.byFolders) {
|
||||
const folder = this.dialogsStorage.getFolder(+folderId);
|
||||
|
||||
for(let dialog of folder) {
|
||||
items.push([dialog]);
|
||||
}
|
||||
}
|
||||
|
||||
return pushHeavyTask({
|
||||
items,
|
||||
process: processDialog,
|
||||
context: this
|
||||
}).then(() => {
|
||||
appStateManager.pushToState('dialogs', dialogs);
|
||||
appStateManager.pushToState('messages', messages);
|
||||
appStateManager.pushToState('filters', this.filtersStorage.filters);
|
||||
appStateManager.pushToState('allDialogsLoaded', this.dialogsStorage.allDialogsLoaded);
|
||||
appStateManager.pushToState('maxSeenMsgId', this.maxSeenId);
|
||||
});
|
||||
});
|
||||
|
||||
appStateManager.getState().then(state => {
|
||||
if(state.maxSeenMsgId) {
|
||||
this.maxSeenId = state.maxSeenMsgId;
|
||||
@ -349,11 +287,75 @@ export class AppMessagesManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
appStateManager.addListener('save', this.saveState);
|
||||
});
|
||||
|
||||
appNotificationsManager.start();
|
||||
}
|
||||
|
||||
private saveState = () => {
|
||||
const messages: any[] = [];
|
||||
const dialogs: Dialog[] = [];
|
||||
const items: any[] = [];
|
||||
|
||||
const processDialog = (dialog: MTDialog.dialog) => {
|
||||
const historyStorage = this.getHistoryStorage(dialog.peerId);
|
||||
const history = [].concat(historyStorage.history.slice);
|
||||
//dialog = copy(dialog);
|
||||
let removeUnread = 0;
|
||||
for(const mid of history) {
|
||||
const message = this.getMessageByPeer(dialog.peerId, mid);
|
||||
if(/* message._ !== 'messageEmpty' && */!message.pFlags.is_outgoing) {
|
||||
messages.push(message);
|
||||
|
||||
if(message.fromId !== dialog.peerId) {
|
||||
appStateManager.setPeer(message.fromId, appPeersManager.getPeer(message.fromId));
|
||||
}
|
||||
|
||||
/* dialog.top_message = message.mid;
|
||||
this.dialogsStorage.generateIndexForDialog(dialog, false, message); */
|
||||
|
||||
break;
|
||||
} else if(message.pFlags && message.pFlags.unread) {
|
||||
++removeUnread;
|
||||
}
|
||||
}
|
||||
|
||||
if(removeUnread && dialog.unread_count) dialog.unread_count -= removeUnread;
|
||||
|
||||
if(dialog.peerId < 0 && dialog.pts) {
|
||||
const newPts = apiUpdatesManager.channelStates[-dialog.peerId].pts;
|
||||
dialog.pts = newPts;
|
||||
}
|
||||
|
||||
dialog.unread_count = Math.max(0, dialog.unread_count);
|
||||
dialogs.push(dialog);
|
||||
|
||||
appStateManager.setPeer(dialog.peerId, appPeersManager.getPeer(dialog.peerId));
|
||||
};
|
||||
|
||||
for(const folderId in this.dialogsStorage.byFolders) {
|
||||
const folder = this.dialogsStorage.getFolder(+folderId);
|
||||
|
||||
for(let dialog of folder) {
|
||||
items.push([dialog]);
|
||||
}
|
||||
}
|
||||
|
||||
return pushHeavyTask({
|
||||
items,
|
||||
process: processDialog,
|
||||
context: this
|
||||
}).then(() => {
|
||||
appStateManager.pushToState('dialogs', dialogs);
|
||||
appStateManager.pushToState('messages', messages);
|
||||
appStateManager.pushToState('filters', this.filtersStorage.filters);
|
||||
appStateManager.pushToState('allDialogsLoaded', this.dialogsStorage.allDialogsLoaded);
|
||||
appStateManager.pushToState('maxSeenMsgId', this.maxSeenId);
|
||||
});
|
||||
};
|
||||
|
||||
public getInputEntities(entities: MessageEntity[]) {
|
||||
var sendEntites = copy(entities);
|
||||
sendEntites.forEach((entity: any) => {
|
||||
|
@ -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