Browse Source

state is ready for testing

master
Eduard Kuzmenko 4 years ago
parent
commit
4318d26f75
  1. 12
      src/components/sidebarLeft/index.ts
  2. 2
      src/lib/appManagers/appDialogsManager.ts
  3. 16
      src/lib/appManagers/appMessagesManager.ts
  4. 4
      src/lib/appManagers/appStateManager.ts
  5. 12
      src/lib/appManagers/appUsersManager.ts
  6. 21
      src/lib/idb.ts
  7. 28
      src/test_indexeddb_getAll.js

12
src/components/sidebarLeft/index.ts

@ -7,8 +7,7 @@ @@ -7,8 +7,7 @@
import { formatNumber } from "../../helpers/number";
import appImManager from "../../lib/appManagers/appImManager";
import appPeersManager from "../../lib/appManagers/appPeersManager";
import appStateManager, { State } from "../../lib/appManagers/appStateManager";
import appStateManager from "../../lib/appManagers/appStateManager";
import appUsersManager from "../../lib/appManagers/appUsersManager";
import rootScope from "../../lib/rootScope";
import { SearchGroup } from "../appSearch";
@ -28,7 +27,7 @@ import AppContactsTab from "./tabs/contacts"; @@ -28,7 +27,7 @@ import AppContactsTab from "./tabs/contacts";
import AppArchivedTab from "./tabs/archivedTab";
import AppAddMembersTab from "./tabs/addMembers";
import { i18n_, LangPackKey } from "../../lib/langPack";
import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu";
import { ButtonMenuItemOptions } from "../buttonMenu";
import CheckboxField from "../checkboxField";
import { isMobileSafari } from "../../helpers/userAgent";
import appNavigationController from "../appNavigationController";
@ -228,6 +227,13 @@ export class AppSidebarLeft extends SidebarSlider { @@ -228,6 +227,13 @@ export class AppSidebarLeft extends SidebarSlider {
});
appUsersManager.getTopPeers();
appStateManager.getState().then(state => {
const recentSearch = state.recentSearch || [];
for(let i = 0, length = recentSearch.length; i < length; ++i) {
appStateManager.requestPeer(recentSearch[i], 'recentSearch');
}
});
}
private initSearch() {

2
src/lib/appManagers/appDialogsManager.ts

@ -507,7 +507,7 @@ export class AppDialogsManager { @@ -507,7 +507,7 @@ export class AppDialogsManager {
return this.loadDialogs();
}).then(() => {
return;
//return;
const isLoadedMain = appMessagesManager.dialogsStorage.isDialogsLoaded(0);
const isLoadedArchive = appMessagesManager.dialogsStorage.isDialogsLoaded(1);

16
src/lib/appManagers/appMessagesManager.ts

@ -3786,7 +3786,8 @@ export class AppMessagesManager { @@ -3786,7 +3786,8 @@ export class AppMessagesManager {
dialog.pFlags.unread_mark = true;
}
rootScope.broadcast('dialogs_multiupdate', {peerId: dialog});
rootScope.broadcast('dialogs_multiupdate', {[peerId]: dialog});
this.dialogsStorage.setDialogToState(dialog);
}
};
@ -3825,6 +3826,7 @@ export class AppMessagesManager { @@ -3825,6 +3826,7 @@ export class AppMessagesManager {
const updatedDialogs: {[peerId: number]: Dialog} = {};
updatedDialogs[peerId] = dialog;
rootScope.broadcast('dialogs_multiupdate', updatedDialogs);
this.dialogsStorage.setDialogToState(dialog);
}
}
};
@ -3892,7 +3894,7 @@ export class AppMessagesManager { @@ -3892,7 +3894,7 @@ export class AppMessagesManager {
foundAffected = true;
}
if(!message.pFlags.out && !threadId && stillUnreadCount === undefined) {
if(!message.pFlags.out && !threadId && foundDialog && stillUnreadCount === undefined) {
newUnreadCount = --foundDialog.unread_count;
}
@ -3916,6 +3918,7 @@ export class AppMessagesManager { @@ -3916,6 +3918,7 @@ export class AppMessagesManager {
}
rootScope.broadcast('dialog_unread', {peerId});
this.dialogsStorage.setDialogToState(foundDialog);
}
if(foundAffected) {
@ -3941,6 +3944,7 @@ export class AppMessagesManager { @@ -3941,6 +3944,7 @@ export class AppMessagesManager {
const message = this.getMessageByPeer(peerId, mid);
if(!message.deleted) {
delete message.pFlags.media_unread;
this.setDialogToStateIfMessageIsTop(message);
}
}
@ -4177,6 +4181,7 @@ export class AppMessagesManager { @@ -4177,6 +4181,7 @@ export class AppMessagesManager {
if(dialog) {
dialog.notify_settings = notify_settings;
rootScope.broadcast('dialog_notify_settings', dialog);
this.dialogsStorage.setDialogToState(dialog);
}
}
};
@ -4217,6 +4222,13 @@ export class AppMessagesManager { @@ -4217,6 +4222,13 @@ export class AppMessagesManager {
}
};
private setDialogToStateIfMessageIsTop(message: any) {
const dialog = this.getDialogOnly(message.peerId);
if(dialog && dialog.top_message === message.mid) {
this.dialogsStorage.setDialogToState(dialog);
}
}
private updateMessageRepliesIfNeeded(threadMessage: MyMessage) {
try { // * на всякий случай, скорее всего это не понадобится
const threadKey = this.getThreadKey(threadMessage);

4
src/lib/appManagers/appStateManager.ts

@ -6,12 +6,10 @@ @@ -6,12 +6,10 @@
import type { Dialog } from './appMessagesManager';
import type { UserAuth } from '../mtproto/mtproto_config';
import type { AppUsersManager, User } from './appUsersManager';
import type { AppChatsManager } from './appChatsManager';
import type { User } from './appUsersManager';
import type { AuthState } from '../../types';
import type FiltersStorage from '../storages/filters';
import type DialogsStorage from '../storages/dialogs';
import type { AppDraftsManager } from './appDraftsManager';
import EventListenerBase from '../../helpers/eventListenerBase';
import rootScope from '../rootScope';
import sessionStorage from '../sessionStorage';

12
src/lib/appManagers/appUsersManager.ts

@ -355,9 +355,13 @@ export class AppUsersManager { @@ -355,9 +355,13 @@ export class AppUsersManager {
rootScope.broadcast('peer_title_edit', user.id);
}
if(appStateManager.isPeerNeeded(userId)) {
this.setUserToStateIfNeeded(user);
}
public setUserToStateIfNeeded(user: User) {
if(appStateManager.isPeerNeeded(user.id)) {
this.storage.set({
[userId]: user
[user.id]: user
});
}
}
@ -561,6 +565,8 @@ export class AppUsersManager { @@ -561,6 +565,8 @@ export class AppUsersManager {
user.status = {_: 'userStatusOffline', was_online: user.status.expires};
rootScope.broadcast('user_update', user.id);
this.setUserToStateIfNeeded(user);
}
}
};
@ -595,6 +601,8 @@ export class AppUsersManager { @@ -595,6 +601,8 @@ export class AppUsersManager {
//user.sortStatus = this.getUserStatusForSort(user.status);
rootScope.broadcast('user_update', id);
this.setUserToStateIfNeeded(user);
}
}

21
src/lib/idb.ts

@ -35,6 +35,8 @@ export type IDBOptions = { @@ -35,6 +35,8 @@ export type IDBOptions = {
version?: number
};
const DEBUG = false;
export default class IDBStorage {
//private static STORAGES: IDBStorage[] = [];
private openDbPromise: Promise<IDBDatabase>;
@ -171,11 +173,11 @@ export default class IDBStorage { @@ -171,11 +173,11 @@ export default class IDBStorage {
return this.getObjectStore('readwrite', (objectStore) => {
return (entryName as string[]).map((entryName) => objectStore.delete(entryName));
}, 'delete: ' + entryName.join(', '));
}, DEBUG ? 'delete: ' + entryName.join(', ') : '');
}
public deleteAll() {
return this.getObjectStore('readwrite', (objectStore) => objectStore.clear(), 'deleteAll');
return this.getObjectStore('readwrite', (objectStore) => objectStore.clear(), DEBUG ? 'deleteAll' : '');
}
public save(entryName: string | string[], value: any | any[]) {
@ -197,7 +199,7 @@ export default class IDBStorage { @@ -197,7 +199,7 @@ export default class IDBStorage {
return this.getObjectStore('readwrite', (objectStore) => {
return (entryName as string[]).map((entryName, idx) => objectStore.put(value[idx], entryName));
}, 'save: ' + entryName.join(', '));
}, DEBUG ? 'save: ' + entryName.join(', ') : '');
}
public saveFile(fileName: string, blob: Blob | Uint8Array) {
@ -284,13 +286,16 @@ export default class IDBStorage { @@ -284,13 +286,16 @@ export default class IDBStorage {
return this.getObjectStore<T>('readonly', (objectStore) => {
return (entryName as string[]).map((entryName) => objectStore.get(entryName));
}, 'get: ' + entryName.join(', '));
}, DEBUG ? 'get: ' + entryName.join(', ') : '');
}
private getObjectStore<T>(mode: IDBTransactionMode, objectStore: (objectStore: IDBObjectStore) => IDBRequest | IDBRequest[], log: string) {
const perf = performance.now();
private getObjectStore<T>(mode: IDBTransactionMode, objectStore: (objectStore: IDBObjectStore) => IDBRequest | IDBRequest[], log?: string) {
let perf: number;
if(log) {
perf = performance.now();
this.log(log + ': start');
}
return this.openDatabase().then((db) => {
return new Promise<T>((resolve, reject) => {
@ -304,7 +309,9 @@ export default class IDBStorage { @@ -304,7 +309,9 @@ export default class IDBStorage {
transaction.oncomplete = (e) => {
clearTimeout(timeout);
if(log) {
this.log(log + ': end', performance.now() - perf);
}
const results = r.map(r => r.result);
resolve(isArray ? results : results[0]);
@ -349,7 +356,7 @@ export default class IDBStorage { @@ -349,7 +356,7 @@ export default class IDBStorage {
}
public getAll<T>(): Promise<T[]> {
return this.getObjectStore<T[]>('readonly', (objectStore) => objectStore.getAll(), 'getAll');
return this.getObjectStore<T[]>('readonly', (objectStore) => objectStore.getAll(), DEBUG ? 'getAll' : '');
}
/* public getAllKeys(): Promise<Array<string>> {

28
src/test_indexeddb_getAll.js

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
var perf = performance.now();
appUsersManager.storage.storage.getAll().then(values => {
console.log('getAll', performance.now() - perf);
});
var perfS = performance.now();
appStorage.storage.get('users').then(values => {
console.log('get', performance.now() - perfS);
});
var user = appUsersManager.getUser();
var users = {};
for(var i = 0; i < 10000; ++i) {
var u = Object.assign({}, user);
u.id = i;
users[i] = u;
}
appUsersManager.storage.set(users);
appStorage.storage.set('users', users);
var types = {};
appStateManager.neededPeers.forEach((value, key) => {
[...value].forEach(type => {
if(!types[type]) types[type] = [];
types[type].push(key);
});
});
Loading…
Cancel
Save