Clear other storages than session on logout
Fix blinking fonts
This commit is contained in:
parent
1a4dc37f22
commit
d3820d817b
@ -25,7 +25,7 @@ const server = useHttp ? http : https;
|
|||||||
let options = {};
|
let options = {};
|
||||||
if(!useHttp) {
|
if(!useHttp) {
|
||||||
options.key = fs.readFileSync(__dirname + '/certs/server-key.pem');
|
options.key = fs.readFileSync(__dirname + '/certs/server-key.pem');
|
||||||
options.cert = s.readFileSync(__dirname + '/certs/server-cert.pem');
|
options.cert = fs.readFileSync(__dirname + '/certs/server-cert.pem');
|
||||||
}
|
}
|
||||||
|
|
||||||
server.createServer(options, app).listen(port, () => {
|
server.createServer(options, app).listen(port, () => {
|
||||||
|
@ -24,7 +24,10 @@ export default class PopupDeleteDialog {
|
|||||||
}; */
|
}; */
|
||||||
|
|
||||||
const callbackLeave = (checked: PopupPeerButtonCallbackCheckboxes) => {
|
const callbackLeave = (checked: PopupPeerButtonCallbackCheckboxes) => {
|
||||||
const promise = appChatsManager.leave(-peerId);
|
const promise = appChatsManager.leave(-peerId).then(() => {
|
||||||
|
return appMessagesManager.flushHistory(-peerId);
|
||||||
|
});
|
||||||
|
|
||||||
onSelect && onSelect(promise);
|
onSelect && onSelect(promise);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,7 +40,7 @@ export default class PopupDeleteDialog {
|
|||||||
if(checked[checkboxes[0].text]) {
|
if(checked[checkboxes[0].text]) {
|
||||||
promise = appChatsManager.delete(-peerId);
|
promise = appChatsManager.delete(-peerId);
|
||||||
} else {
|
} else {
|
||||||
promise = appChatsManager.leave(-peerId);
|
return callbackLeave(checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/index.ts
21
src/index.ts
@ -248,6 +248,11 @@ console.timeEnd('get storage1'); */
|
|||||||
//import('./vendor/dateFormat');
|
//import('./vendor/dateFormat');
|
||||||
|
|
||||||
const langPromise = I18n.default.getCacheLangPack();
|
const langPromise = I18n.default.getCacheLangPack();
|
||||||
|
|
||||||
|
function loadFonts(): Promise<void> {
|
||||||
|
// @ts-ignore
|
||||||
|
return 'fonts' in document ? Promise.all(['400 1rem Roboto', '500 1rem Roboto'].map(font => document.fonts.load(font))) : Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
const [state, langPack] = await Promise.all([
|
const [state, langPack] = await Promise.all([
|
||||||
appStateManager.default.getState(),
|
appStateManager.default.getState(),
|
||||||
@ -263,6 +268,16 @@ console.timeEnd('get storage1'); */
|
|||||||
I18n.default.getLangPack(langPack.lang_code);
|
I18n.default.getLangPack(langPack.lang_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fadeInWhenFontsReady(elem: HTMLElement, promise: Promise<void>) {
|
||||||
|
elem.style.opacity = '0';
|
||||||
|
|
||||||
|
promise.then(() => {
|
||||||
|
window.requestAnimationFrame(() => {
|
||||||
|
elem.style.opacity = '';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('got state, time:', performance.now() - perf);
|
console.log('got state, time:', performance.now() - perf);
|
||||||
|
|
||||||
const authState = state.authState;
|
const authState = state.authState;
|
||||||
@ -271,11 +286,14 @@ console.timeEnd('get storage1'); */
|
|||||||
|
|
||||||
const el = document.getElementById('auth-pages');
|
const el = document.getElementById('auth-pages');
|
||||||
if(el) {
|
if(el) {
|
||||||
const scrollable = el.querySelector('.scrollable');
|
const scrollable = el.querySelector('.scrollable') as HTMLElement;
|
||||||
if((!touchSupport.isTouchSupported || isMobileSafari)) {
|
if((!touchSupport.isTouchSupported || isMobileSafari)) {
|
||||||
scrollable.classList.add('no-scrollbar');
|
scrollable.classList.add('no-scrollbar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
fadeInWhenFontsReady(scrollable, 'fonts' in document ? document.fonts.ready : Promise.resolve());
|
||||||
|
|
||||||
const placeholder = document.createElement('div');
|
const placeholder = document.createElement('div');
|
||||||
placeholder.classList.add('auth-placeholder');
|
placeholder.classList.add('auth-placeholder');
|
||||||
|
|
||||||
@ -348,6 +366,7 @@ console.timeEnd('get storage1'); */
|
|||||||
}, 500); */
|
}, 500); */
|
||||||
} else {
|
} else {
|
||||||
console.log('Will mount IM page:', Date.now() / 1000);
|
console.log('Will mount IM page:', Date.now() / 1000);
|
||||||
|
fadeInWhenFontsReady(document.getElementById('main-columns'), loadFonts());
|
||||||
(await import('./pages/pageIm')).default.mount();
|
(await import('./pages/pageIm')).default.mount();
|
||||||
//getNearestDc();
|
//getNearestDc();
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,15 @@
|
|||||||
|
|
||||||
//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 { Update } from '../../layer';
|
import { Update } from '../../layer';
|
||||||
import { logger, LogTypes } from '../logger';
|
import { logger, LogTypes } from '../logger';
|
||||||
import apiManager from '../mtproto/mtprotoworker';
|
import apiManager from '../mtproto/mtprotoworker';
|
||||||
import rootScope from '../rootScope';
|
import rootScope from '../rootScope';
|
||||||
//import networkerFactory from '../mtproto/networkerFactory';
|
//import networkerFactory from '../mtproto/networkerFactory';
|
||||||
|
import appUsersManager from "./appUsersManager";
|
||||||
import appChatsManager from "./appChatsManager";
|
import appChatsManager from "./appChatsManager";
|
||||||
import appPeersManager from "./appPeersManager";
|
import appPeersManager from "./appPeersManager";
|
||||||
import appStateManager from './appStateManager';
|
import appStateManager from './appStateManager';
|
||||||
import appUsersManager from "./appUsersManager";
|
|
||||||
|
|
||||||
type UpdatesState = {
|
type UpdatesState = {
|
||||||
pendingPtsUpdates: {pts: number, pts_count: number}[],
|
pendingPtsUpdates: {pts: number, pts_count: number}[],
|
||||||
@ -51,7 +50,7 @@ export class ApiUpdatesManager {
|
|||||||
public channelStates: {[channelId: number]: UpdatesState} = {};
|
public channelStates: {[channelId: number]: UpdatesState} = {};
|
||||||
private attached = false;
|
private attached = false;
|
||||||
|
|
||||||
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() {
|
private setProxy() {
|
||||||
@ -60,17 +59,21 @@ export class ApiUpdatesManager {
|
|||||||
set: function(target: ApiUpdatesManager['updatesState'], key: keyof ApiUpdatesManager['updatesState'], value: ApiUpdatesManager['updatesState'][typeof key]) {
|
set: function(target: ApiUpdatesManager['updatesState'], key: keyof ApiUpdatesManager['updatesState'], value: ApiUpdatesManager['updatesState'][typeof key]) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
target[key] = value;
|
target[key] = value;
|
||||||
const us = self.updatesState;
|
self.saveUpdatesState();
|
||||||
appStateManager.pushToState('updates', {
|
|
||||||
seq: us.seq,
|
|
||||||
pts: us.pts,
|
|
||||||
date: us.date
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public saveUpdatesState() {
|
||||||
|
const us = this.updatesState;
|
||||||
|
appStateManager.pushToState('updates', {
|
||||||
|
seq: us.seq,
|
||||||
|
pts: us.pts,
|
||||||
|
date: us.date
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private popPendingSeqUpdate() {
|
private popPendingSeqUpdate() {
|
||||||
const state = this.updatesState;
|
const state = this.updatesState;
|
||||||
const nextSeq = state.seq + 1;
|
const nextSeq = state.seq + 1;
|
||||||
@ -132,7 +135,7 @@ export class ApiUpdatesManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.debug && this.log('pop pending pts updates', goodPts, curState.pendingPtsUpdates.slice(0, goodIndex + 1));
|
this.debug && this.log.debug('pop pending pts updates', goodPts, curState.pendingPtsUpdates.slice(0, goodIndex + 1));
|
||||||
|
|
||||||
curState.pts = goodPts;
|
curState.pts = goodPts;
|
||||||
for(let i = 0; i <= goodIndex; ++i) {
|
for(let i = 0; i <= goodIndex; ++i) {
|
||||||
@ -172,7 +175,7 @@ export class ApiUpdatesManager {
|
|||||||
//ignoreSyncLoading: options.ignoreSyncLoading
|
//ignoreSyncLoading: options.ignoreSyncLoading
|
||||||
};
|
};
|
||||||
|
|
||||||
this.debug && this.log('processUpdateMessage', updateMessage);
|
this.debug && this.log.debug('processUpdateMessage', updateMessage);
|
||||||
|
|
||||||
switch(updateMessage._) {
|
switch(updateMessage._) {
|
||||||
case 'updatesTooLong':
|
case 'updatesTooLong':
|
||||||
@ -186,7 +189,7 @@ export class ApiUpdatesManager {
|
|||||||
|
|
||||||
case 'updateShortMessage':
|
case 'updateShortMessage':
|
||||||
case 'updateShortChatMessage': {
|
case 'updateShortChatMessage': {
|
||||||
this.debug && this.log('updateShortMessage | updateShortChatMessage', {...updateMessage});
|
this.debug && this.log.debug('updateShortMessage | updateShortChatMessage', {...updateMessage});
|
||||||
const isOut = updateMessage.pFlags.out;
|
const isOut = updateMessage.pFlags.out;
|
||||||
const fromId = updateMessage.from_id || (isOut ? rootScope.myId : updateMessage.user_id);
|
const fromId = updateMessage.from_id || (isOut ? rootScope.myId : updateMessage.user_id);
|
||||||
const toId = updateMessage.chat_id
|
const toId = updateMessage.chat_id
|
||||||
@ -249,10 +252,10 @@ export class ApiUpdatesManager {
|
|||||||
}, {
|
}, {
|
||||||
timeout: 0x7fffffff
|
timeout: 0x7fffffff
|
||||||
}).then((differenceResult) => {
|
}).then((differenceResult) => {
|
||||||
this.debug && this.log('Get diff result', differenceResult);
|
this.debug && this.log.debug('Get diff result', differenceResult);
|
||||||
|
|
||||||
if(differenceResult._ === 'updates.differenceEmpty') {
|
if(differenceResult._ === 'updates.differenceEmpty') {
|
||||||
this.debug && this.log('apply empty diff', differenceResult.seq);
|
this.debug && this.log.debug('apply empty diff', differenceResult.seq);
|
||||||
updatesState.date = differenceResult.date;
|
updatesState.date = differenceResult.date;
|
||||||
updatesState.seq = differenceResult.seq;
|
updatesState.seq = differenceResult.seq;
|
||||||
return;
|
return;
|
||||||
@ -307,7 +310,7 @@ export class ApiUpdatesManager {
|
|||||||
if(differenceResult._ === 'updates.differenceSlice') {
|
if(differenceResult._ === 'updates.differenceSlice') {
|
||||||
return this.getDifference();
|
return this.getDifference();
|
||||||
} else {
|
} else {
|
||||||
this.debug && this.log('finished get diff');
|
this.debug && this.log.debug('finished get diff');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -337,16 +340,16 @@ export class ApiUpdatesManager {
|
|||||||
pts: channelState.pts,
|
pts: channelState.pts,
|
||||||
limit: 30
|
limit: 30
|
||||||
}, {timeout: 0x7fffffff}).then((differenceResult) => {
|
}, {timeout: 0x7fffffff}).then((differenceResult) => {
|
||||||
this.debug && this.log('Get channel diff result', differenceResult)
|
this.debug && this.log.debug('Get channel diff result', differenceResult)
|
||||||
channelState.pts = 'pts' in differenceResult ? differenceResult.pts : undefined;
|
channelState.pts = 'pts' in differenceResult ? differenceResult.pts : undefined;
|
||||||
|
|
||||||
if(differenceResult._ === 'updates.channelDifferenceEmpty') {
|
if(differenceResult._ === 'updates.channelDifferenceEmpty') {
|
||||||
this.debug && this.log('apply channel empty diff', differenceResult);
|
this.debug && this.log.debug('apply channel empty diff', differenceResult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(differenceResult._ === 'updates.channelDifferenceTooLong') {
|
if(differenceResult._ === 'updates.channelDifferenceTooLong') {
|
||||||
this.debug && this.log('channel diff too long', differenceResult);
|
this.debug && this.log.debug('channel diff too long', differenceResult);
|
||||||
delete this.channelStates[channelId];
|
delete this.channelStates[channelId];
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -358,12 +361,12 @@ export class ApiUpdatesManager {
|
|||||||
appChatsManager.saveApiChats(differenceResult.chats);
|
appChatsManager.saveApiChats(differenceResult.chats);
|
||||||
|
|
||||||
// Should be first because of updateMessageID
|
// Should be first because of updateMessageID
|
||||||
this.debug && this.log('applying', differenceResult.other_updates.length, 'channel other updates');
|
this.debug && this.log.debug('applying', differenceResult.other_updates.length, 'channel other updates');
|
||||||
differenceResult.other_updates.forEach((update) => {
|
differenceResult.other_updates.forEach((update) => {
|
||||||
this.saveUpdate(update);
|
this.saveUpdate(update);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.debug && this.log('applying', differenceResult.new_messages.length, 'channel new messages');
|
this.debug && this.log.debug('applying', differenceResult.new_messages.length, 'channel new messages');
|
||||||
differenceResult.new_messages.forEach((apiMessage) => {
|
differenceResult.new_messages.forEach((apiMessage) => {
|
||||||
this.saveUpdate({
|
this.saveUpdate({
|
||||||
_: 'updateNewChannelMessage',
|
_: 'updateNewChannelMessage',
|
||||||
@ -373,13 +376,13 @@ export class ApiUpdatesManager {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.debug && this.log('apply channel diff', channelState.pts);
|
this.debug && this.log.debug('apply channel diff', channelState.pts);
|
||||||
|
|
||||||
if(differenceResult._ === 'updates.channelDifference' &&
|
if(differenceResult._ === 'updates.channelDifference' &&
|
||||||
!differenceResult.pFlags['final']) {
|
!differenceResult.pFlags['final']) {
|
||||||
return this.getChannelDifference(channelId);
|
return this.getChannelDifference(channelId);
|
||||||
} else {
|
} else {
|
||||||
this.debug && this.log('finished channel get diff');
|
this.debug && this.log.debug('finished channel get diff');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -593,7 +596,7 @@ export class ApiUpdatesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public saveUpdate(update: Update) {
|
public saveUpdate(update: Update) {
|
||||||
this.log('saveUpdate', update);
|
this.debug && this.log('saveUpdate', update);
|
||||||
rootScope.dispatchEvent(update._, update as any);
|
rootScope.dispatchEvent(update._, update as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,6 +621,7 @@ export class ApiUpdatesManager {
|
|||||||
this.updatesState.seq = stateResult.seq;
|
this.updatesState.seq = stateResult.seq;
|
||||||
this.updatesState.pts = stateResult.pts;
|
this.updatesState.pts = stateResult.pts;
|
||||||
this.updatesState.date = stateResult.date;
|
this.updatesState.date = stateResult.date;
|
||||||
|
this.saveUpdatesState();
|
||||||
//setTimeout(() => {
|
//setTimeout(() => {
|
||||||
this.updatesState.syncLoading = null;
|
this.updatesState.syncLoading = null;
|
||||||
resolve();
|
resolve();
|
||||||
@ -639,7 +643,7 @@ export class ApiUpdatesManager {
|
|||||||
|
|
||||||
Object.assign(this.updatesState, state);
|
Object.assign(this.updatesState, state);
|
||||||
|
|
||||||
this.log('will get difference', copy(state));
|
this.log('will get difference', Object.assign({}, state));
|
||||||
|
|
||||||
this.getDifference(true)/* .finally(() => {
|
this.getDifference(true)/* .finally(() => {
|
||||||
if(this.updatesState.syncLoading) {
|
if(this.updatesState.syncLoading) {
|
||||||
|
@ -19,7 +19,6 @@ import apiManager from '../mtproto/mtprotoworker';
|
|||||||
import { RichTextProcessor } from "../richtextprocessor";
|
import { RichTextProcessor } from "../richtextprocessor";
|
||||||
import rootScope from "../rootScope";
|
import rootScope from "../rootScope";
|
||||||
import apiUpdatesManager from "./apiUpdatesManager";
|
import apiUpdatesManager from "./apiUpdatesManager";
|
||||||
import appMessagesManager from "./appMessagesManager";
|
|
||||||
import appPeersManager from "./appPeersManager";
|
import appPeersManager from "./appPeersManager";
|
||||||
import appProfileManager from "./appProfileManager";
|
import appProfileManager from "./appProfileManager";
|
||||||
import appStateManager from "./appStateManager";
|
import appStateManager from "./appStateManager";
|
||||||
@ -637,12 +636,8 @@ export class AppChatsManager {
|
|||||||
}).then(this.onChatUpdated.bind(this, id));
|
}).then(this.onChatUpdated.bind(this, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public leaveChat(id: number, flushHistory = true) {
|
public leaveChat(id: number) {
|
||||||
let promise: Promise<any> = this.deleteChatUser(id, appUsersManager.getSelf().id)
|
return this.deleteChatUser(id, appUsersManager.getSelf().id);
|
||||||
if(flushHistory) promise = promise.then(() => {
|
|
||||||
return appMessagesManager.flushHistory(-id);
|
|
||||||
});
|
|
||||||
return promise;;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public leave(id: number) {
|
public leave(id: number) {
|
||||||
|
@ -213,7 +213,7 @@ export class AppDialogsManager {
|
|||||||
title: HTMLElement
|
title: HTMLElement
|
||||||
}
|
}
|
||||||
} = {};
|
} = {};
|
||||||
private showFiltersTimeout: number;
|
private showFiltersPromise: Promise<void>;
|
||||||
private allUnreadCount: HTMLElement;
|
private allUnreadCount: HTMLElement;
|
||||||
|
|
||||||
private accumulateArchivedTimeout: number;
|
private accumulateArchivedTimeout: number;
|
||||||
@ -491,16 +491,22 @@ export class AppDialogsManager {
|
|||||||
//selectTab(0);
|
//selectTab(0);
|
||||||
(this.folders.menu.firstElementChild as HTMLElement).click();
|
(this.folders.menu.firstElementChild as HTMLElement).click();
|
||||||
appMessagesManager.construct();
|
appMessagesManager.construct();
|
||||||
appStateManager.getState().then((state) => {
|
appStateManager.getState().then(async(state) => {
|
||||||
appNotificationsManager.getNotifyPeerTypeSettings();
|
appNotificationsManager.getNotifyPeerTypeSettings();
|
||||||
|
|
||||||
const getFiltersPromise = appMessagesManager.filtersStorage.getDialogFilters();
|
const renderFiltersPromise = appMessagesManager.filtersStorage.getDialogFilters().then((filters) => {
|
||||||
getFiltersPromise.then((filters) => {
|
|
||||||
for(const filter of filters) {
|
for(const filter of filters) {
|
||||||
this.addFilter(filter);
|
this.addFilter(filter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(state.filters && Object.keys(state.filters).length) {
|
||||||
|
await renderFiltersPromise;
|
||||||
|
if(this.showFiltersPromise) {
|
||||||
|
await this.showFiltersPromise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(appStateManager.storagesResults.dialogs.length) {
|
if(appStateManager.storagesResults.dialogs.length) {
|
||||||
appDraftsManager.getAllDrafts();
|
appDraftsManager.getAllDrafts();
|
||||||
appDraftsManager.addMissedDialogs();
|
appDraftsManager.addMissedDialogs();
|
||||||
@ -706,12 +712,15 @@ export class AppDialogsManager {
|
|||||||
title: titleSpan
|
title: titleSpan
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!this.showFiltersTimeout && Object.keys(this.filtersRendered).length > 1) {
|
if(!this.showFiltersPromise && Object.keys(this.filtersRendered).length > 1) {
|
||||||
this.showFiltersTimeout = window.setTimeout(() => {
|
this.showFiltersPromise = new Promise<void>((resolve) => {
|
||||||
this.showFiltersTimeout = 0;
|
window.setTimeout(() => {
|
||||||
this.folders.menuScrollContainer.classList.remove('hide');
|
this.showFiltersPromise = undefined;
|
||||||
this.setFiltersUnreadCount();
|
this.folders.menuScrollContainer.classList.remove('hide');
|
||||||
}, 0);
|
this.setFiltersUnreadCount();
|
||||||
|
resolve();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,8 +305,8 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public construct() {
|
public construct() {
|
||||||
this.dialogsStorage = new DialogsStorage(this, appChatsManager, appPeersManager, appUsersManager, appDraftsManager, appNotificationsManager, appStateManager, apiUpdatesManager, serverTimeManager);
|
|
||||||
this.filtersStorage = new FiltersStorage(this, appPeersManager, appUsersManager, appNotificationsManager, appStateManager, apiUpdatesManager, /* apiManager, */ rootScope);
|
this.filtersStorage = new FiltersStorage(this, appPeersManager, appUsersManager, appNotificationsManager, appStateManager, apiUpdatesManager, /* apiManager, */ rootScope);
|
||||||
|
this.dialogsStorage = new DialogsStorage(this, appChatsManager, appPeersManager, appUsersManager, appDraftsManager, appNotificationsManager, appStateManager, apiUpdatesManager, serverTimeManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getInputEntities(entities: MessageEntity[]) {
|
public getInputEntities(entities: MessageEntity[]) {
|
||||||
@ -2362,7 +2362,6 @@ export class AppMessagesManager {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'messageActionPhoneCall':
|
case 'messageActionPhoneCall':
|
||||||
delete message.fromId;
|
|
||||||
message.action.type =
|
message.action.type =
|
||||||
(message.pFlags.out ? 'out_' : 'in_') +
|
(message.pFlags.out ? 'out_' : 'in_') +
|
||||||
(
|
(
|
||||||
|
@ -38,8 +38,9 @@ export type IDBOptions = {
|
|||||||
const DEBUG = false;
|
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>;
|
||||||
|
private db: IDBDatabase;
|
||||||
private storageIsAvailable = true;
|
private storageIsAvailable = true;
|
||||||
|
|
||||||
private log: ReturnType<typeof logger>;
|
private log: ReturnType<typeof logger>;
|
||||||
@ -57,7 +58,33 @@ export default class IDBStorage {
|
|||||||
|
|
||||||
this.openDatabase(true);
|
this.openDatabase(true);
|
||||||
|
|
||||||
//IDBStorage.STORAGES.push(this);
|
IDBStorage.STORAGES.push(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static closeDatabases() {
|
||||||
|
this.STORAGES.forEach(storage => {
|
||||||
|
const db = storage.db;
|
||||||
|
if(db) {
|
||||||
|
db.onclose = () => {};
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static deleteDatabase() {
|
||||||
|
this.closeDatabases();
|
||||||
|
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
const deleteRequest = indexedDB.deleteDatabase(Database.name);
|
||||||
|
|
||||||
|
deleteRequest.onerror = () => {
|
||||||
|
reject();
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteRequest.onsuccess = () => {
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public isAvailable() {
|
public isAvailable() {
|
||||||
@ -134,7 +161,7 @@ export default class IDBStorage {
|
|||||||
this.log.error('onversionchange, lol?');
|
this.log.error('onversionchange, lol?');
|
||||||
};
|
};
|
||||||
|
|
||||||
resolve(db);
|
resolve(this.db = db);
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onerror = (event) => {
|
request.onerror = (event) => {
|
||||||
|
@ -26,6 +26,7 @@ import { bytesFromHex, bytesToHex } from '../../helpers/bytes';
|
|||||||
import { ctx, isSafari } from '../../helpers/userAgent';
|
import { ctx, isSafari } from '../../helpers/userAgent';
|
||||||
import App from '../../config/app';
|
import App from '../../config/app';
|
||||||
import { MOUNT_CLASS_TO } from '../../config/debug';
|
import { MOUNT_CLASS_TO } from '../../config/debug';
|
||||||
|
import IDBStorage from '../idb';
|
||||||
|
|
||||||
/// #if !MTPROTO_WORKER
|
/// #if !MTPROTO_WORKER
|
||||||
import rootScope from '../rootScope';
|
import rootScope from '../rootScope';
|
||||||
@ -149,10 +150,8 @@ export class ApiManager {
|
|||||||
|
|
||||||
this.baseDcId = 0;
|
this.baseDcId = 0;
|
||||||
//this.telegramMeNotify(false);
|
//this.telegramMeNotify(false);
|
||||||
const promise = sessionStorage.clear();
|
IDBStorage.closeDatabases();
|
||||||
promise.finally(() => {
|
self.postMessage({type: 'clear'});
|
||||||
self.postMessage({type: 'reload'});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(clear, 1e3);
|
setTimeout(clear, 1e3);
|
||||||
|
@ -19,6 +19,7 @@ import { UserAuth } from './mtproto_config';
|
|||||||
import type { MTMessage } from './networker';
|
import type { MTMessage } from './networker';
|
||||||
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
|
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
|
||||||
import Socket from './transports/websocket';
|
import Socket from './transports/websocket';
|
||||||
|
import IDBStorage from '../idb';
|
||||||
|
|
||||||
type Task = {
|
type Task = {
|
||||||
taskId: number,
|
taskId: number,
|
||||||
@ -87,8 +88,11 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
|
|
||||||
this.registerServiceWorker();
|
this.registerServiceWorker();
|
||||||
|
|
||||||
this.addTaskListener('reload', () => {
|
this.addTaskListener('clear', () => {
|
||||||
location.reload();
|
const promise = IDBStorage.deleteDatabase();
|
||||||
|
promise.finally(() => {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addTaskListener('connectionStatusChange', (task: any) => {
|
this.addTaskListener('connectionStatusChange', (task: any) => {
|
||||||
|
@ -141,7 +141,7 @@ export default class MTPNetworker {
|
|||||||
const suffix = this.isFileUpload ? '-U' : this.isFileDownload ? '-D' : '';
|
const suffix = this.isFileUpload ? '-U' : this.isFileDownload ? '-D' : '';
|
||||||
this.name = 'NET-' + dcId + suffix;
|
this.name = 'NET-' + dcId + suffix;
|
||||||
//this.log = logger(this.name, this.upload && this.dcId === 2 ? LogLevels.debug | LogLevels.warn | LogLevels.log | LogLevels.error : LogLevels.error);
|
//this.log = logger(this.name, this.upload && this.dcId === 2 ? LogLevels.debug | LogLevels.warn | LogLevels.log | LogLevels.error : LogLevels.error);
|
||||||
this.log = logger(this.name, /* LogTypes.Log | LogTypes.Debug | */LogTypes.Error | LogTypes.Warn);
|
this.log = logger(this.name, LogTypes.Log | /* LogTypes.Debug | */LogTypes.Error | LogTypes.Warn);
|
||||||
this.log('constructor'/* , this.authKey, this.authKeyID, this.serverSalt */);
|
this.log('constructor'/* , this.authKey, this.authKeyID, this.serverSalt */);
|
||||||
|
|
||||||
// Test resend after bad_server_salt
|
// Test resend after bad_server_salt
|
||||||
@ -596,7 +596,7 @@ export default class MTPNetworker {
|
|||||||
// this.log('parse for', message)
|
// this.log('parse for', message)
|
||||||
this.parseResponse(result).then((response) => {
|
this.parseResponse(result).then((response) => {
|
||||||
if(Modes.debug) {
|
if(Modes.debug) {
|
||||||
this.log('Server response', response);
|
this.log.debug('Server response', response);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.processMessage(response.response, response.messageId, response.sessionId);
|
this.processMessage(response.response, response.messageId, response.sessionId);
|
||||||
@ -735,7 +735,7 @@ export default class MTPNetworker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(this.debug) {
|
if(this.debug) {
|
||||||
this.log('pushResend:', messageId, sentMessage, this.pendingMessages, delay);
|
this.log.debug('pushResend:', messageId, sentMessage, this.pendingMessages, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scheduleRequest(delay);
|
this.scheduleRequest(delay);
|
||||||
@ -1089,7 +1089,7 @@ export default class MTPNetworker {
|
|||||||
|
|
||||||
public sendEncryptedRequest(message: MTMessage) {
|
public sendEncryptedRequest(message: MTMessage) {
|
||||||
return this.getEncryptedOutput(message).then(requestData => {
|
return this.getEncryptedOutput(message).then(requestData => {
|
||||||
this.debug && this.log('sendEncryptedRequest: launching message into space:', message, [message.msg_id].concat(message.inner || []));
|
this.debug && this.log.debug('sendEncryptedRequest: launching message into space:', message, [message.msg_id].concat(message.inner || []));
|
||||||
|
|
||||||
const promise: Promise<Uint8Array> = this.transport.send(requestData) as any;
|
const promise: Promise<Uint8Array> = this.transport.send(requestData) as any;
|
||||||
/// #if !MTPROTO_HTTP && !MTPROTO_HTTP_UPLOAD
|
/// #if !MTPROTO_HTTP && !MTPROTO_HTTP_UPLOAD
|
||||||
@ -1325,7 +1325,7 @@ export default class MTPNetworker {
|
|||||||
|
|
||||||
public reqResendMessage(msgId: string) {
|
public reqResendMessage(msgId: string) {
|
||||||
if(this.debug) {
|
if(this.debug) {
|
||||||
this.log('Req resend', msgId);
|
this.log.debug('Req resend', msgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pendingResends.push(msgId);
|
this.pendingResends.push(msgId);
|
||||||
|
@ -196,4 +196,8 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteDatabase() {
|
||||||
|
return IDBStorage.deleteDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,3 +263,8 @@
|
|||||||
margin-top: 1.1875rem; // * verified with mockup
|
margin-top: 1.1875rem; // * verified with mockup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#auth-pages > .scrollable, #main-columns {
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity var(--transition-standard-in);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user