state is ready for testing
This commit is contained in:
parent
64efb48923
commit
4318d26f75
@ -7,8 +7,7 @@
|
|||||||
|
|
||||||
import { formatNumber } from "../../helpers/number";
|
import { formatNumber } from "../../helpers/number";
|
||||||
import appImManager from "../../lib/appManagers/appImManager";
|
import appImManager from "../../lib/appManagers/appImManager";
|
||||||
import appPeersManager from "../../lib/appManagers/appPeersManager";
|
import appStateManager from "../../lib/appManagers/appStateManager";
|
||||||
import appStateManager, { State } from "../../lib/appManagers/appStateManager";
|
|
||||||
import appUsersManager from "../../lib/appManagers/appUsersManager";
|
import appUsersManager from "../../lib/appManagers/appUsersManager";
|
||||||
import rootScope from "../../lib/rootScope";
|
import rootScope from "../../lib/rootScope";
|
||||||
import { SearchGroup } from "../appSearch";
|
import { SearchGroup } from "../appSearch";
|
||||||
@ -28,7 +27,7 @@ import AppContactsTab from "./tabs/contacts";
|
|||||||
import AppArchivedTab from "./tabs/archivedTab";
|
import AppArchivedTab from "./tabs/archivedTab";
|
||||||
import AppAddMembersTab from "./tabs/addMembers";
|
import AppAddMembersTab from "./tabs/addMembers";
|
||||||
import { i18n_, LangPackKey } from "../../lib/langPack";
|
import { i18n_, LangPackKey } from "../../lib/langPack";
|
||||||
import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu";
|
import { ButtonMenuItemOptions } from "../buttonMenu";
|
||||||
import CheckboxField from "../checkboxField";
|
import CheckboxField from "../checkboxField";
|
||||||
import { isMobileSafari } from "../../helpers/userAgent";
|
import { isMobileSafari } from "../../helpers/userAgent";
|
||||||
import appNavigationController from "../appNavigationController";
|
import appNavigationController from "../appNavigationController";
|
||||||
@ -228,6 +227,13 @@ export class AppSidebarLeft extends SidebarSlider {
|
|||||||
});
|
});
|
||||||
|
|
||||||
appUsersManager.getTopPeers();
|
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() {
|
private initSearch() {
|
||||||
|
@ -507,7 +507,7 @@ export class AppDialogsManager {
|
|||||||
|
|
||||||
return this.loadDialogs();
|
return this.loadDialogs();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return;
|
//return;
|
||||||
|
|
||||||
const isLoadedMain = appMessagesManager.dialogsStorage.isDialogsLoaded(0);
|
const isLoadedMain = appMessagesManager.dialogsStorage.isDialogsLoaded(0);
|
||||||
const isLoadedArchive = appMessagesManager.dialogsStorage.isDialogsLoaded(1);
|
const isLoadedArchive = appMessagesManager.dialogsStorage.isDialogsLoaded(1);
|
||||||
|
@ -3786,7 +3786,8 @@ export class AppMessagesManager {
|
|||||||
dialog.pFlags.unread_mark = true;
|
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 {
|
|||||||
const updatedDialogs: {[peerId: number]: Dialog} = {};
|
const updatedDialogs: {[peerId: number]: Dialog} = {};
|
||||||
updatedDialogs[peerId] = dialog;
|
updatedDialogs[peerId] = dialog;
|
||||||
rootScope.broadcast('dialogs_multiupdate', updatedDialogs);
|
rootScope.broadcast('dialogs_multiupdate', updatedDialogs);
|
||||||
|
this.dialogsStorage.setDialogToState(dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -3892,7 +3894,7 @@ export class AppMessagesManager {
|
|||||||
foundAffected = true;
|
foundAffected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!message.pFlags.out && !threadId && stillUnreadCount === undefined) {
|
if(!message.pFlags.out && !threadId && foundDialog && stillUnreadCount === undefined) {
|
||||||
newUnreadCount = --foundDialog.unread_count;
|
newUnreadCount = --foundDialog.unread_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3914,8 +3916,9 @@ export class AppMessagesManager {
|
|||||||
foundDialog.unread_count = newUnreadCount;
|
foundDialog.unread_count = newUnreadCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootScope.broadcast('dialog_unread', {peerId});
|
rootScope.broadcast('dialog_unread', {peerId});
|
||||||
|
this.dialogsStorage.setDialogToState(foundDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(foundAffected) {
|
if(foundAffected) {
|
||||||
@ -3941,6 +3944,7 @@ export class AppMessagesManager {
|
|||||||
const message = this.getMessageByPeer(peerId, mid);
|
const message = this.getMessageByPeer(peerId, mid);
|
||||||
if(!message.deleted) {
|
if(!message.deleted) {
|
||||||
delete message.pFlags.media_unread;
|
delete message.pFlags.media_unread;
|
||||||
|
this.setDialogToStateIfMessageIsTop(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4177,6 +4181,7 @@ export class AppMessagesManager {
|
|||||||
if(dialog) {
|
if(dialog) {
|
||||||
dialog.notify_settings = notify_settings;
|
dialog.notify_settings = notify_settings;
|
||||||
rootScope.broadcast('dialog_notify_settings', dialog);
|
rootScope.broadcast('dialog_notify_settings', dialog);
|
||||||
|
this.dialogsStorage.setDialogToState(dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -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) {
|
private updateMessageRepliesIfNeeded(threadMessage: MyMessage) {
|
||||||
try { // * на всякий случай, скорее всего это не понадобится
|
try { // * на всякий случай, скорее всего это не понадобится
|
||||||
const threadKey = this.getThreadKey(threadMessage);
|
const threadKey = this.getThreadKey(threadMessage);
|
||||||
|
@ -6,12 +6,10 @@
|
|||||||
|
|
||||||
import type { Dialog } from './appMessagesManager';
|
import type { Dialog } from './appMessagesManager';
|
||||||
import type { UserAuth } from '../mtproto/mtproto_config';
|
import type { UserAuth } from '../mtproto/mtproto_config';
|
||||||
import type { AppUsersManager, User } from './appUsersManager';
|
import type { User } from './appUsersManager';
|
||||||
import type { AppChatsManager } from './appChatsManager';
|
|
||||||
import type { AuthState } from '../../types';
|
import type { AuthState } from '../../types';
|
||||||
import type FiltersStorage from '../storages/filters';
|
import type FiltersStorage from '../storages/filters';
|
||||||
import type DialogsStorage from '../storages/dialogs';
|
import type DialogsStorage from '../storages/dialogs';
|
||||||
import type { AppDraftsManager } from './appDraftsManager';
|
|
||||||
import EventListenerBase from '../../helpers/eventListenerBase';
|
import EventListenerBase from '../../helpers/eventListenerBase';
|
||||||
import rootScope from '../rootScope';
|
import rootScope from '../rootScope';
|
||||||
import sessionStorage from '../sessionStorage';
|
import sessionStorage from '../sessionStorage';
|
||||||
|
@ -355,9 +355,13 @@ export class AppUsersManager {
|
|||||||
rootScope.broadcast('peer_title_edit', user.id);
|
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({
|
this.storage.set({
|
||||||
[userId]: user
|
[user.id]: user
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,6 +565,8 @@ export class AppUsersManager {
|
|||||||
|
|
||||||
user.status = {_: 'userStatusOffline', was_online: user.status.expires};
|
user.status = {_: 'userStatusOffline', was_online: user.status.expires};
|
||||||
rootScope.broadcast('user_update', user.id);
|
rootScope.broadcast('user_update', user.id);
|
||||||
|
|
||||||
|
this.setUserToStateIfNeeded(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -595,6 +601,8 @@ export class AppUsersManager {
|
|||||||
|
|
||||||
//user.sortStatus = this.getUserStatusForSort(user.status);
|
//user.sortStatus = this.getUserStatusForSort(user.status);
|
||||||
rootScope.broadcast('user_update', id);
|
rootScope.broadcast('user_update', id);
|
||||||
|
|
||||||
|
this.setUserToStateIfNeeded(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ export type IDBOptions = {
|
|||||||
version?: number
|
version?: number
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DEBUG = false;
|
||||||
|
|
||||||
export default class IDBStorage {
|
export default class IDBStorage {
|
||||||
//private static STORAGES: IDBStorage[] = [];
|
//private static STORAGES: IDBStorage[] = [];
|
||||||
private openDbPromise: Promise<IDBDatabase>;
|
private openDbPromise: Promise<IDBDatabase>;
|
||||||
@ -171,11 +173,11 @@ export default class IDBStorage {
|
|||||||
|
|
||||||
return this.getObjectStore('readwrite', (objectStore) => {
|
return this.getObjectStore('readwrite', (objectStore) => {
|
||||||
return (entryName as string[]).map((entryName) => objectStore.delete(entryName));
|
return (entryName as string[]).map((entryName) => objectStore.delete(entryName));
|
||||||
}, 'delete: ' + entryName.join(', '));
|
}, DEBUG ? 'delete: ' + entryName.join(', ') : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteAll() {
|
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[]) {
|
public save(entryName: string | string[], value: any | any[]) {
|
||||||
@ -197,7 +199,7 @@ export default class IDBStorage {
|
|||||||
|
|
||||||
return this.getObjectStore('readwrite', (objectStore) => {
|
return this.getObjectStore('readwrite', (objectStore) => {
|
||||||
return (entryName as string[]).map((entryName, idx) => objectStore.put(value[idx], entryName));
|
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) {
|
public saveFile(fileName: string, blob: Blob | Uint8Array) {
|
||||||
@ -284,13 +286,16 @@ export default class IDBStorage {
|
|||||||
|
|
||||||
return this.getObjectStore<T>('readonly', (objectStore) => {
|
return this.getObjectStore<T>('readonly', (objectStore) => {
|
||||||
return (entryName as string[]).map((entryName) => objectStore.get(entryName));
|
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) {
|
private getObjectStore<T>(mode: IDBTransactionMode, objectStore: (objectStore: IDBObjectStore) => IDBRequest | IDBRequest[], log?: string) {
|
||||||
const perf = performance.now();
|
let perf: number;
|
||||||
|
|
||||||
this.log(log + ': start');
|
if(log) {
|
||||||
|
perf = performance.now();
|
||||||
|
this.log(log + ': start');
|
||||||
|
}
|
||||||
|
|
||||||
return this.openDatabase().then((db) => {
|
return this.openDatabase().then((db) => {
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
@ -304,7 +309,9 @@ export default class IDBStorage {
|
|||||||
transaction.oncomplete = (e) => {
|
transaction.oncomplete = (e) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|
||||||
this.log(log + ': end', performance.now() - perf);
|
if(log) {
|
||||||
|
this.log(log + ': end', performance.now() - perf);
|
||||||
|
}
|
||||||
|
|
||||||
const results = r.map(r => r.result);
|
const results = r.map(r => r.result);
|
||||||
resolve(isArray ? results : results[0]);
|
resolve(isArray ? results : results[0]);
|
||||||
@ -349,7 +356,7 @@ export default class IDBStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getAll<T>(): Promise<T[]> {
|
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>> {
|
/* public getAllKeys(): Promise<Array<string>> {
|
||||||
|
28
src/test_indexeddb_getAll.js
Normal file
28
src/test_indexeddb_getAll.js
Normal file
@ -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…
x
Reference in New Issue
Block a user