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;
|
||||||
@ -578,16 +567,18 @@ export class ApiUpdatesManager {
|
|||||||
if(this.attached) return;
|
if(this.attached) return;
|
||||||
|
|
||||||
//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,10 +21,10 @@ 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) => {
|
||||||
|
@ -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 => {
|
appStateManager.getState().then(state => {
|
||||||
if(state.maxSeenMsgId) {
|
if(state.maxSeenMsgId) {
|
||||||
this.maxSeenId = state.maxSeenMsgId;
|
this.maxSeenId = state.maxSeenMsgId;
|
||||||
@ -349,11 +287,75 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appStateManager.addListener('save', this.saveState);
|
||||||
});
|
});
|
||||||
|
|
||||||
appNotificationsManager.start();
|
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[]) {
|
public getInputEntities(entities: MessageEntity[]) {
|
||||||
var sendEntites = copy(entities);
|
var sendEntites = copy(entities);
|
||||||
sendEntites.forEach((entity: any) => {
|
sendEntites.forEach((entity: any) => {
|
||||||
|
@ -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