alpha state fix
This commit is contained in:
parent
5e159f5519
commit
d132ef290a
@ -54,6 +54,23 @@ export class ApiUpdatesManager {
|
|||||||
private log = logger('UPDATES', LogTypes.Error | LogTypes.Warn/* | LogTypes.Log | LogTypes.Debug */);
|
private log = logger('UPDATES', LogTypes.Error | LogTypes.Warn/* | LogTypes.Log | LogTypes.Debug */);
|
||||||
private debug = DEBUG;
|
private debug = DEBUG;
|
||||||
|
|
||||||
|
private setProxy() {
|
||||||
|
const self = this;
|
||||||
|
this.updatesState = new Proxy(this.updatesState, {
|
||||||
|
set: function(target: ApiUpdatesManager['updatesState'], key: keyof ApiUpdatesManager['updatesState'], value: ApiUpdatesManager['updatesState'][typeof key]) {
|
||||||
|
// @ts-ignore
|
||||||
|
target[key] = value;
|
||||||
|
const us = self.updatesState;
|
||||||
|
appStateManager.pushToState('updates', {
|
||||||
|
seq: us.seq,
|
||||||
|
pts: us.pts,
|
||||||
|
date: us.date
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private popPendingSeqUpdate() {
|
private popPendingSeqUpdate() {
|
||||||
const state = this.updatesState;
|
const state = this.updatesState;
|
||||||
const nextSeq = state.seq + 1;
|
const nextSeq = state.seq + 1;
|
||||||
@ -633,15 +650,7 @@ export class ApiUpdatesManager {
|
|||||||
apiManager.setUpdatesProcessor(this.processUpdateMessage);
|
apiManager.setUpdatesProcessor(this.processUpdateMessage);
|
||||||
|
|
||||||
this.updatesState.syncLoading.then(() => {
|
this.updatesState.syncLoading.then(() => {
|
||||||
// * false for test purposes
|
this.setProxy();
|
||||||
/* false && */appStateManager.addEventListener('save', async() => {
|
|
||||||
const us = this.updatesState;
|
|
||||||
appStateManager.pushToState('updates', {
|
|
||||||
seq: us.seq,
|
|
||||||
pts: us.pts,
|
|
||||||
date: us.date
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,21 @@ export class AppChatsManager {
|
|||||||
updateChannelUserTyping: this.onUpdateUserTyping
|
updateChannelUserTyping: this.onUpdateUserTyping
|
||||||
});
|
});
|
||||||
|
|
||||||
appStateManager.getState().then((state) => {
|
let storageChats: Chat[];
|
||||||
|
const getStorageChatsPromise = this.storage.getAll().then(chats => {
|
||||||
|
storageChats = chats as any;
|
||||||
|
});
|
||||||
|
|
||||||
|
appStateManager.addLoadPromise(getStorageChatsPromise).then((state) => {
|
||||||
|
if(storageChats.length) {
|
||||||
|
this.chats = {};
|
||||||
|
for(let i = 0, length = storageChats.length; i < length; ++i) {
|
||||||
|
const user = storageChats[i];
|
||||||
|
this.chats[user.id] = user;
|
||||||
|
}
|
||||||
|
} else if(state.chats) {
|
||||||
this.chats = state.chats;
|
this.chats = state.chats;
|
||||||
|
}
|
||||||
|
|
||||||
appStateManager.addEventListener('peerNeeded', (peerId: number) => {
|
appStateManager.addEventListener('peerNeeded', (peerId: number) => {
|
||||||
if(peerId > 0 || this.storage.getFromCache(-peerId)) {
|
if(peerId > 0 || this.storage.getFromCache(-peerId)) {
|
||||||
|
@ -507,10 +507,11 @@ export class AppDialogsManager {
|
|||||||
|
|
||||||
return this.loadDialogs();
|
return this.loadDialogs();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const allDialogsLoaded = appMessagesManager.dialogsStorage.allDialogsLoaded;
|
const isLoadedMain = appMessagesManager.dialogsStorage.isDialogsLoaded(0);
|
||||||
const wasLoaded = allDialogsLoaded[0] || allDialogsLoaded[1];
|
const isLoadedArchive = appMessagesManager.dialogsStorage.isDialogsLoaded(1);
|
||||||
const a: Promise<any> = allDialogsLoaded[0] ? Promise.resolve() : appMessagesManager.getConversationsAll('', 0);
|
const wasLoaded = isLoadedMain || isLoadedArchive;
|
||||||
const b: Promise<any> = allDialogsLoaded[1] ? Promise.resolve() : appMessagesManager.getConversationsAll('', 1);
|
const a: Promise<any> = isLoadedMain ? Promise.resolve() : appMessagesManager.getConversationsAll('', 0);
|
||||||
|
const b: Promise<any> = isLoadedArchive ? Promise.resolve() : appMessagesManager.getConversationsAll('', 1);
|
||||||
a.finally(() => {
|
a.finally(() => {
|
||||||
b.then(() => {
|
b.then(() => {
|
||||||
this.accumulateArchivedUnread();
|
this.accumulateArchivedUnread();
|
||||||
|
@ -32,10 +32,6 @@ export class AppDraftsManager {
|
|||||||
constructor() {
|
constructor() {
|
||||||
appStateManager.getState().then(state => {
|
appStateManager.getState().then(state => {
|
||||||
this.drafts = state.drafts;
|
this.drafts = state.drafts;
|
||||||
|
|
||||||
appStateManager.addEventListener('save', async() => {
|
|
||||||
appStateManager.pushToState('drafts', this.drafts);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rootScope.addMultipleEventsListeners({
|
rootScope.addMultipleEventsListeners({
|
||||||
@ -100,6 +96,8 @@ export class AppDraftsManager {
|
|||||||
delete this.drafts[key];
|
delete this.drafts[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appStateManager.pushToState('drafts', this.drafts);
|
||||||
|
|
||||||
if(options.notify) {
|
if(options.notify) {
|
||||||
// console.warn(dT(), 'save draft', peerId, apiDraft, options)
|
// console.warn(dT(), 'save draft', peerId, apiDraft, options)
|
||||||
rootScope.broadcast('draft_updated', {
|
rootScope.broadcast('draft_updated', {
|
||||||
|
@ -194,7 +194,7 @@ export class AppMessagesManager {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.dialogsStorage = new DialogsStorage(this, appChatsManager, appPeersManager, appUsersManager, appDraftsManager, appNotificationsManager, appStateManager, apiUpdatesManager, serverTimeManager);
|
this.dialogsStorage = new DialogsStorage(this, appChatsManager, appPeersManager, appUsersManager, appDraftsManager, appNotificationsManager, appStateManager, apiUpdatesManager, serverTimeManager);
|
||||||
this.filtersStorage = new FiltersStorage(this, appPeersManager, appUsersManager, appNotificationsManager, apiUpdatesManager, /* apiManager, */ rootScope);
|
this.filtersStorage = new FiltersStorage(this, appPeersManager, appUsersManager, appNotificationsManager, appStateManager, apiUpdatesManager, /* apiManager, */ rootScope);
|
||||||
|
|
||||||
rootScope.addMultipleEventsListeners({
|
rootScope.addMultipleEventsListeners({
|
||||||
updateMessageID: this.onUpdateMessageId,
|
updateMessageID: this.onUpdateMessageId,
|
||||||
@ -303,111 +303,11 @@ export class AppMessagesManager {
|
|||||||
if(state.maxSeenMsgId) {
|
if(state.maxSeenMsgId) {
|
||||||
this.maxSeenId = 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) {
|
|
||||||
forEachReverse(state.dialogs, dialog => {
|
|
||||||
dialog.top_message = this.getServerMessageId(dialog.top_message); // * fix outgoing message to avoid copying dialog
|
|
||||||
|
|
||||||
this.dialogsStorage.saveDialog(dialog);
|
|
||||||
|
|
||||||
// ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись
|
|
||||||
const message = this.getMessageByPeer(dialog.peerId, dialog.top_message);
|
|
||||||
if(message.deleted) {
|
|
||||||
this.reloadConversation(dialog.peerId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
appStateManager.addEventListener('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);
|
|
||||||
for(const mid of history) {
|
|
||||||
const message = this.getMessageByPeer(dialog.peerId, mid);
|
|
||||||
if(!message.pFlags.is_outgoing) {
|
|
||||||
messages.push(message);
|
|
||||||
|
|
||||||
if(message.fromId !== dialog.peerId) {
|
|
||||||
appStateManager.requestPeer(message.fromId, 'topMessage_' + dialog.peerId, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dialog.peerId < 0 && dialog.pts) {
|
|
||||||
const newPts = apiUpdatesManager.channelStates[-dialog.peerId].pts;
|
|
||||||
dialog.pts = newPts;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogs.push(dialog);
|
|
||||||
|
|
||||||
appStateManager.requestPeer(dialog.peerId, 'dialog');
|
|
||||||
};
|
|
||||||
|
|
||||||
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) => {
|
||||||
@ -1807,7 +1707,7 @@ export class AppMessagesManager {
|
|||||||
if(!dialogsResult.dialogs.length ||
|
if(!dialogsResult.dialogs.length ||
|
||||||
!count ||
|
!count ||
|
||||||
dialogs.length >= count) {
|
dialogs.length >= count) {
|
||||||
this.dialogsStorage.allDialogsLoaded[folderId] = true;
|
this.dialogsStorage.setDialogsLoaded(folderId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasPrepend) {
|
if(hasPrepend) {
|
||||||
@ -4498,6 +4398,7 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.maxSeenId = maxId;
|
this.maxSeenId = maxId;
|
||||||
|
appStateManager.pushToState('maxSeenMsgId', maxId);
|
||||||
|
|
||||||
apiManager.invokeApi('messages.receivedMessages', {
|
apiManager.invokeApi('messages.receivedMessages', {
|
||||||
max_id: this.getServerMessageId(maxId)
|
max_id: this.getServerMessageId(maxId)
|
||||||
|
@ -162,12 +162,12 @@ export class AppStateManager extends EventListenerBase<{
|
|||||||
peerUnneeded: (peerId: number) => void,
|
peerUnneeded: (peerId: number) => void,
|
||||||
}> {
|
}> {
|
||||||
public static STATE_INIT = STATE_INIT;
|
public static STATE_INIT = STATE_INIT;
|
||||||
public loaded: Promise<State>;
|
private loaded: Promise<State>;
|
||||||
|
private loadPromises: Promise<any>[] = [];
|
||||||
|
private loadAllPromise: Promise<any>;
|
||||||
private log = logger('STATE'/* , LogLevels.error */);
|
private log = logger('STATE'/* , LogLevels.error */);
|
||||||
|
|
||||||
private state: State;
|
private state: State;
|
||||||
private savePromise: Promise<void>;
|
|
||||||
private tempId = 0;
|
|
||||||
|
|
||||||
private neededPeers: Map<number, Set<string>> = new Map();
|
private neededPeers: Map<number, Set<string>> = new Map();
|
||||||
private singlePeerMap: Map<string, number> = new Map();
|
private singlePeerMap: Map<string, number> = new Map();
|
||||||
@ -177,10 +177,10 @@ export class AppStateManager extends EventListenerBase<{
|
|||||||
this.loadSavedState();
|
this.loadSavedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadSavedState() {
|
public loadSavedState(): Promise<State> {
|
||||||
if(this.loaded) return this.loaded;
|
if(this.loadAllPromise) return this.loadAllPromise;
|
||||||
//console.time('load state');
|
//console.time('load state');
|
||||||
return this.loaded = new Promise((resolve) => {
|
this.loaded = new Promise((resolve) => {
|
||||||
Promise.all(ALL_KEYS.concat('user_auth' as any).map(key => sessionStorage.get(key))).then((arr) => {
|
Promise.all(ALL_KEYS.concat('user_auth' as any).map(key => sessionStorage.get(key))).then((arr) => {
|
||||||
let state: State = {};
|
let state: State = {};
|
||||||
|
|
||||||
@ -255,48 +255,26 @@ export class AppStateManager extends EventListenerBase<{
|
|||||||
|
|
||||||
//console.timeEnd('load state');
|
//console.timeEnd('load state');
|
||||||
resolve(this.state);
|
resolve(this.state);
|
||||||
}).catch(resolve).finally(() => {
|
}).catch(resolve);
|
||||||
setInterval(() => {
|
|
||||||
this.tempId++;
|
|
||||||
this.saveState();
|
|
||||||
}, 10000);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return this.addLoadPromise(this.loaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
public addLoadPromise(promise: Promise<any>) {
|
||||||
|
if(!this.loaded) {
|
||||||
|
return this.loadSavedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loadPromises.push(promise);
|
||||||
|
return this.loadAllPromise = Promise.all(this.loadPromises)
|
||||||
|
.then(() => this.state, () => this.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getState() {
|
public getState() {
|
||||||
return this.state === undefined ? this.loadSavedState() : Promise.resolve(this.state);
|
return this.state === undefined ? this.loadSavedState() : Promise.resolve(this.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveState() {
|
|
||||||
if(this.state === undefined || this.savePromise) return;
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
const tempId = this.tempId;
|
|
||||||
this.savePromise = getHeavyAnimationPromise().then(() => {
|
|
||||||
return Promise.all(this.dispatchEvent('save', this.state))
|
|
||||||
.then(() => getHeavyAnimationPromise())
|
|
||||||
.then(() => sessionStorage.set(this.state))
|
|
||||||
.then(() => {
|
|
||||||
this.savePromise = null;
|
|
||||||
|
|
||||||
if(this.tempId !== tempId) {
|
|
||||||
this.saveState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//let perf = performance.now();
|
|
||||||
|
|
||||||
//this.log('saveState: event time:', performance.now() - perf);
|
|
||||||
|
|
||||||
//const pinnedOrders = appMessagesManager.dialogsStorage.pinnedOrders;
|
|
||||||
|
|
||||||
//perf = performance.now();
|
|
||||||
|
|
||||||
//this.log('saveState: storage set time:', performance.now() - perf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public setByKey(key: string, value: any) {
|
public setByKey(key: string, value: any) {
|
||||||
setDeepProperty(this.state, key, value);
|
setDeepProperty(this.state, key, value);
|
||||||
rootScope.broadcast('settings_updated', {key, value});
|
rootScope.broadcast('settings_updated', {key, value});
|
||||||
|
@ -113,8 +113,21 @@ export class AppUsersManager {
|
|||||||
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
|
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
appStateManager.getState().then((state) => {
|
let storageUsers: User[];
|
||||||
|
const getStorageUsersPromise = this.storage.getAll().then(users => {
|
||||||
|
storageUsers = users as any;
|
||||||
|
});
|
||||||
|
|
||||||
|
appStateManager.addLoadPromise(getStorageUsersPromise).then((state) => {
|
||||||
|
if(storageUsers.length) {
|
||||||
|
this.users = {};
|
||||||
|
for(let i = 0, length = storageUsers.length; i < length; ++i) {
|
||||||
|
const user = storageUsers[i];
|
||||||
|
this.users[user.id] = user;
|
||||||
|
}
|
||||||
|
} else if(state.users) {
|
||||||
this.users = state.users;
|
this.users = state.users;
|
||||||
|
}
|
||||||
|
|
||||||
const contactsList = state.contactsList;
|
const contactsList = state.contactsList;
|
||||||
if(contactsList && Array.isArray(contactsList)) {
|
if(contactsList && Array.isArray(contactsList)) {
|
||||||
@ -122,20 +135,11 @@ export class AppUsersManager {
|
|||||||
this.pushContact(userId);
|
this.pushContact(userId);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(this.contactsList.size) {
|
if(contactsList.length) {
|
||||||
this.contactsFillPromise = Promise.resolve(this.contactsList);
|
this.contactsFillPromise = Promise.resolve(this.contactsList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appStateManager.addEventListener('save', async() => {
|
|
||||||
const contactsList = [...this.contactsList];
|
|
||||||
for(const userId of contactsList) {
|
|
||||||
appStateManager.requestPeer(userId, 'contacts');
|
|
||||||
}
|
|
||||||
|
|
||||||
appStateManager.pushToState('contactsList', contactsList);
|
|
||||||
});
|
|
||||||
|
|
||||||
appStateManager.addEventListener('peerNeeded', (peerId: number) => {
|
appStateManager.addEventListener('peerNeeded', (peerId: number) => {
|
||||||
if(peerId < 0 || this.storage.getFromCache(peerId)) {
|
if(peerId < 0 || this.storage.getFromCache(peerId)) {
|
||||||
return;
|
return;
|
||||||
@ -156,6 +160,11 @@ export class AppUsersManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onContactsModified() {
|
||||||
|
const contactsList = [...this.contactsList];
|
||||||
|
appStateManager.pushToState('contactsList', contactsList);
|
||||||
|
}
|
||||||
|
|
||||||
public fillContacts() {
|
public fillContacts() {
|
||||||
if(this.contactsFillPromise && this.updatedContactsList) {
|
if(this.contactsFillPromise && this.updatedContactsList) {
|
||||||
return this.contactsFillPromise;
|
return this.contactsFillPromise;
|
||||||
@ -170,6 +179,8 @@ export class AppUsersManager {
|
|||||||
result.contacts.forEach((contact) => {
|
result.contacts.forEach((contact) => {
|
||||||
this.pushContact(contact.user_id);
|
this.pushContact(contact.user_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.onContactsModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.contactsFillPromise = promise;
|
this.contactsFillPromise = promise;
|
||||||
@ -201,6 +212,7 @@ export class AppUsersManager {
|
|||||||
public pushContact(userId: number) {
|
public pushContact(userId: number) {
|
||||||
this.contactsList.add(userId);
|
this.contactsList.add(userId);
|
||||||
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
|
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
|
||||||
|
appStateManager.requestPeer(userId, 'contacts');
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserSearchText(id: number) {
|
public getUserSearchText(id: number) {
|
||||||
@ -756,12 +768,13 @@ export class AppUsersManager {
|
|||||||
const curIsContact = this.isContact(userId);
|
const curIsContact = this.isContact(userId);
|
||||||
if(isContact !== curIsContact) {
|
if(isContact !== curIsContact) {
|
||||||
if(isContact) {
|
if(isContact) {
|
||||||
this.contactsList.add(userId)
|
this.pushContact(userId);
|
||||||
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
|
|
||||||
} else {
|
} else {
|
||||||
this.contactsList.delete(userId);
|
this.contactsList.delete(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.onContactsModified();
|
||||||
|
|
||||||
rootScope.broadcast('contacts_update', userId);
|
rootScope.broadcast('contacts_update', userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
|
|||||||
} */
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getAll() {
|
||||||
|
return this.storage.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
public async set(obj: Partial<Storage>, onlyLocal = false) {
|
public async set(obj: Partial<Storage>, onlyLocal = false) {
|
||||||
//console.log('storageSetValue', obj, callback, arguments);
|
//console.log('storageSetValue', obj, callback, arguments);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ export default class DialogsStorage {
|
|||||||
private dialogs: {[peerId: string]: Dialog} = {};
|
private dialogs: {[peerId: string]: Dialog} = {};
|
||||||
public byFolders: {[folderId: number]: Dialog[]} = {};
|
public byFolders: {[folderId: number]: Dialog[]} = {};
|
||||||
|
|
||||||
public allDialogsLoaded: {[folder_id: number]: boolean};
|
private allDialogsLoaded: {[folder_id: number]: boolean};
|
||||||
private dialogsOffsetDate: {[folder_id: number]: number};
|
private dialogsOffsetDate: {[folder_id: number]: number};
|
||||||
private pinnedOrders: {[folder_id: number]: number[]};
|
private pinnedOrders: {[folder_id: number]: number[]};
|
||||||
private dialogsNum: number;
|
private dialogsNum: number;
|
||||||
@ -84,6 +84,40 @@ export default class DialogsStorage {
|
|||||||
|
|
||||||
updatePinnedDialogs: this.onUpdatePinnedDialogs,
|
updatePinnedDialogs: this.onUpdatePinnedDialogs,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let storageDialogs: Dialog[];
|
||||||
|
const getStorageDialogsPromise = this.storage.getAll().then(dialogs => {
|
||||||
|
storageDialogs = dialogs as any;
|
||||||
|
|
||||||
|
forEachReverse(storageDialogs, dialog => {
|
||||||
|
dialog.top_message = this.appMessagesManager.getServerMessageId(dialog.top_message); // * fix outgoing message to avoid copying dialog
|
||||||
|
|
||||||
|
this.saveDialog(dialog);
|
||||||
|
|
||||||
|
if(dialog.topMessage) {
|
||||||
|
this.appMessagesManager.saveMessages([dialog.topMessage]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись
|
||||||
|
const message = this.appMessagesManager.getMessageByPeer(dialog.peerId, dialog.top_message);
|
||||||
|
if(message.deleted) {
|
||||||
|
this.appMessagesManager.reloadConversation(dialog.peerId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
appStateManager.addLoadPromise(getStorageDialogsPromise).then((state) => {
|
||||||
|
this.allDialogsLoaded = state.allDialogsLoaded || {};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public isDialogsLoaded(folderId: number) {
|
||||||
|
return !!this.allDialogsLoaded[folderId];
|
||||||
|
}
|
||||||
|
|
||||||
|
public setDialogsLoaded(folderId: number, loaded: boolean) {
|
||||||
|
this.allDialogsLoaded[folderId] = loaded;
|
||||||
|
this.appStateManager.pushToState('allDialogsLoaded', this.allDialogsLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset() {
|
public reset() {
|
||||||
@ -512,11 +546,12 @@ export default class DialogsStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query || this.allDialogsLoaded[realFolderId] || curDialogStorage.length >= offset + limit) {
|
const loadedAll = this.isDialogsLoaded(realFolderId);
|
||||||
|
if(query || loadedAll || curDialogStorage.length >= offset + limit) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
dialogs: curDialogStorage.slice(offset, offset + limit),
|
dialogs: curDialogStorage.slice(offset, offset + limit),
|
||||||
count: this.allDialogsLoaded[realFolderId] ? curDialogStorage.length : null,
|
count: loadedAll ? curDialogStorage.length : null,
|
||||||
isEnd: this.allDialogsLoaded[realFolderId] && (offset + limit) >= curDialogStorage.length
|
isEnd: loadedAll && (offset + limit) >= curDialogStorage.length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,7 +572,7 @@ export default class DialogsStorage {
|
|||||||
return {
|
return {
|
||||||
dialogs: curDialogStorage.slice(offset, offset + limit),
|
dialogs: curDialogStorage.slice(offset, offset + limit),
|
||||||
count: messagesDialogs._ === 'messages.dialogs' ? messagesDialogs.dialogs.length : messagesDialogs.count,
|
count: messagesDialogs._ === 'messages.dialogs' ? messagesDialogs.dialogs.length : messagesDialogs.count,
|
||||||
isEnd: this.allDialogsLoaded[realFolderId] && (offset + limit) >= curDialogStorage.length
|
isEnd: this.isDialogsLoaded(realFolderId) && (offset + limit) >= curDialogStorage.length
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import type {AppNotificationsManager} from "../appManagers/appNotificationsManag
|
|||||||
import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager";
|
import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager";
|
||||||
import apiManager from "../mtproto/mtprotoworker";
|
import apiManager from "../mtproto/mtprotoworker";
|
||||||
import { forEachReverse } from "../../helpers/array";
|
import { forEachReverse } from "../../helpers/array";
|
||||||
|
import { AppStateManager } from "../appManagers/appStateManager";
|
||||||
|
|
||||||
export type MyDialogFilter = Modify<DialogFilter, {
|
export type MyDialogFilter = Modify<DialogFilter, {
|
||||||
pinned_peers: number[],
|
pinned_peers: number[],
|
||||||
@ -29,16 +30,25 @@ const START_ORDER_INDEX = 1;
|
|||||||
|
|
||||||
export default class FiltersStorage {
|
export default class FiltersStorage {
|
||||||
public filters: {[filterId: string]: MyDialogFilter} = {};
|
public filters: {[filterId: string]: MyDialogFilter} = {};
|
||||||
public orderIndex = START_ORDER_INDEX;
|
private orderIndex = START_ORDER_INDEX;
|
||||||
|
|
||||||
constructor(private appMessagesManager: AppMessagesManager,
|
constructor(private appMessagesManager: AppMessagesManager,
|
||||||
private appPeersManager: AppPeersManager,
|
private appPeersManager: AppPeersManager,
|
||||||
private appUsersManager: AppUsersManager,
|
private appUsersManager: AppUsersManager,
|
||||||
private appNotificationsManager: AppNotificationsManager,
|
private appNotificationsManager: AppNotificationsManager,
|
||||||
|
private appStateManager: AppStateManager,
|
||||||
private apiUpdatesManager: ApiUpdatesManager,
|
private apiUpdatesManager: ApiUpdatesManager,
|
||||||
/* private apiManager: ApiManagerProxy, */
|
/* private apiManager: ApiManagerProxy, */
|
||||||
private rootScope: typeof _rootScope) {
|
private rootScope: typeof _rootScope) {
|
||||||
|
|
||||||
|
this.appStateManager.getState().then((state) => {
|
||||||
|
if(state.filters) {
|
||||||
|
for(const filterId in state.filters) {
|
||||||
|
this.saveDialogFilter(state.filters[filterId], false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
rootScope.addMultipleEventsListeners({
|
rootScope.addMultipleEventsListeners({
|
||||||
updateDialogFilter: this.onUpdateDialogFilter,
|
updateDialogFilter: this.onUpdateDialogFilter,
|
||||||
|
|
||||||
@ -71,6 +81,8 @@ export default class FiltersStorage {
|
|||||||
this.rootScope.broadcast('filter_delete', this.filters[update.id]);
|
this.rootScope.broadcast('filter_delete', this.filters[update.id]);
|
||||||
delete this.filters[update.id];
|
delete this.filters[update.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.appStateManager.pushToState('filters', this.filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onUpdateDialogFilterOrder = (update: Update.updateDialogFilterOrder) => {
|
private onUpdateDialogFilterOrder = (update: Update.updateDialogFilterOrder) => {
|
||||||
@ -84,6 +96,8 @@ export default class FiltersStorage {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.rootScope.broadcast('filter_order', update.order);
|
this.rootScope.broadcast('filter_order', update.order);
|
||||||
|
|
||||||
|
this.appStateManager.pushToState('filters', this.filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
public testDialogForFilter(dialog: Dialog, filter: MyDialogFilter) {
|
public testDialogForFilter(dialog: Dialog, filter: MyDialogFilter) {
|
||||||
@ -264,5 +278,7 @@ export default class FiltersStorage {
|
|||||||
} else {
|
} else {
|
||||||
filter.orderIndex = this.orderIndex++;
|
filter.orderIndex = this.orderIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.appStateManager.pushToState('filters', this.filters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,6 @@ const page = new Page('page-authCode', true, onFirstMount, (_authCode: typeof au
|
|||||||
replaceContent(sentTypeElement, i18n(key, args));
|
replaceContent(sentTypeElement, i18n(key, args));
|
||||||
|
|
||||||
appStateManager.pushToState('authState', {_: 'authStateAuthCode', sentCode: _authCode});
|
appStateManager.pushToState('authState', {_: 'authStateAuthCode', sentCode: _authCode});
|
||||||
appStateManager.saveState();
|
|
||||||
}, () => {
|
}, () => {
|
||||||
codeInput.focus();
|
codeInput.focus();
|
||||||
});
|
});
|
||||||
|
@ -140,7 +140,6 @@ const page = new Page('page-password', true, onFirstMount, null, () => {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
appStateManager.pushToState('authState', {_: 'authStatePassword'});
|
appStateManager.pushToState('authState', {_: 'authStatePassword'});
|
||||||
appStateManager.saveState();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default page;
|
export default page;
|
||||||
|
@ -516,7 +516,6 @@ const page = new Page('page-sign', true, onFirstMount, () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appStateManager.pushToState('authState', {_: 'authStateSignIn'});
|
appStateManager.pushToState('authState', {_: 'authStateSignIn'});
|
||||||
appStateManager.saveState();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default page;
|
export default page;
|
||||||
|
@ -169,7 +169,6 @@ const page = new Page('page-signUp', true, onFirstMount, (_authCode: typeof auth
|
|||||||
authCode = _authCode;
|
authCode = _authCode;
|
||||||
|
|
||||||
appStateManager.pushToState('authState', {_: 'authStateSignUp', authCode: _authCode});
|
appStateManager.pushToState('authState', {_: 'authStateSignUp', authCode: _authCode});
|
||||||
appStateManager.saveState();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default page;
|
export default page;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user