Browse Source

Merge branch 'master' into master

master
wang chenyu 4 years ago committed by GitHub
parent
commit
10a32650da
  1. 2
      server.js
  2. 7
      src/components/popups/deleteDialog.ts
  3. 2
      src/config/app.ts
  4. 47
      src/index.ts
  5. 52
      src/lib/appManagers/apiUpdatesManager.ts
  6. 9
      src/lib/appManagers/appChatsManager.ts
  7. 29
      src/lib/appManagers/appDialogsManager.ts
  8. 3
      src/lib/appManagers/appMessagesManager.ts
  9. 33
      src/lib/idb.ts
  10. 7
      src/lib/mtproto/apiManager.ts
  11. 8
      src/lib/mtproto/mtprotoworker.ts
  12. 10
      src/lib/mtproto/networker.ts
  13. 4
      src/lib/storage.ts
  14. 5
      src/scss/partials/pages/_pages.scss

2
server.js

@ -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, () => {

7
src/components/popups/deleteDialog.ts

@ -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);
} }
} }

2
src/config/app.ts

@ -12,7 +12,7 @@
const App = { const App = {
id: 1025907, id: 1025907,
hash: '452b0359b988148995f22ff0f4229750', hash: '452b0359b988148995f22ff0f4229750',
version: '0.4.3', version: '0.5.0',
langPackVersion: '0.1.6', langPackVersion: '0.1.6',
langPack: 'macos', langPack: 'macos',
langPackCode: 'en', langPackCode: 'en',

47
src/index.ts

@ -249,6 +249,11 @@ console.timeEnd('get storage1'); */
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(),
langPromise langPromise
@ -263,6 +268,19 @@ console.timeEnd('get storage1'); */
I18n.default.getLangPack(langPack.lang_code); I18n.default.getLangPack(langPack.lang_code);
} }
/**
* won't fire if font is loaded too fast
*/
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;
@ -270,12 +288,16 @@ console.timeEnd('get storage1'); */
console.log('Will mount auth page:', authState._, Date.now() / 1000); console.log('Will mount auth page:', authState._, Date.now() / 1000);
const el = document.getElementById('auth-pages'); const el = document.getElementById('auth-pages');
let scrollable: HTMLElement;
if(el) { if(el) {
const scrollable = el.querySelector('.scrollable'); scrollable = el.querySelector('.scrollable') as HTMLElement;
if((!touchSupport.isTouchSupported || isMobileSafari)) { if((!touchSupport.isTouchSupported || isMobileSafari)) {
scrollable.classList.add('no-scrollbar'); scrollable.classList.add('no-scrollbar');
} }
// * don't remove this line
scrollable.style.opacity = '0';
const placeholder = document.createElement('div'); const placeholder = document.createElement('div');
placeholder.classList.add('auth-placeholder'); placeholder.classList.add('auth-placeholder');
@ -283,26 +305,38 @@ console.timeEnd('get storage1'); */
scrollable.append(placeholder.cloneNode()); scrollable.append(placeholder.cloneNode());
} }
let pagePromise: Promise<void>;
//langPromise.then(async() => { //langPromise.then(async() => {
switch(authState._) { switch(authState._) {
case 'authStateSignIn': case 'authStateSignIn':
(await import('./pages/pageSignIn')).default.mount(); pagePromise = (await import('./pages/pageSignIn')).default.mount();
break; break;
case 'authStateSignQr': case 'authStateSignQr':
(await import('./pages/pageSignQR')).default.mount(); pagePromise = (await import('./pages/pageSignQR')).default.mount();
break; break;
case 'authStateAuthCode': case 'authStateAuthCode':
(await import('./pages/pageAuthCode')).default.mount(authState.sentCode); pagePromise = (await import('./pages/pageAuthCode')).default.mount(authState.sentCode);
break; break;
case 'authStatePassword': case 'authStatePassword':
(await import('./pages/pagePassword')).default.mount(); pagePromise = (await import('./pages/pagePassword')).default.mount();
break; break;
case 'authStateSignUp': case 'authStateSignUp':
(await import('./pages/pageSignUp')).default.mount(authState.authCode); pagePromise = (await import('./pages/pageSignUp')).default.mount(authState.authCode);
break; break;
} }
//}); //});
if(scrollable) {
// wait for text appear
if(pagePromise) {
await pagePromise;
}
// @ts-ignore
const promise = 'fonts' in document ? document.fonts.ready : Promise.resolve();
fadeInWhenFontsReady(scrollable, promise);
}
/* computeCheck(password, { /* computeCheck(password, {
current_algo: { current_algo: {
salt1, salt1,
@ -348,6 +382,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();
} }

52
src/lib/appManagers/apiUpdatesManager.ts

@ -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) {

9
src/lib/appManagers/appChatsManager.ts

@ -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) {

29
src/lib/appManagers/appDialogsManager.ts

@ -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);
});
} }
} }

3
src/lib/appManagers/appMessagesManager.ts

@ -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_') +
( (

33
src/lib/idb.ts

@ -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) => {

7
src/lib/mtproto/apiManager.ts

@ -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);

8
src/lib/mtproto/mtprotoworker.ts

@ -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) => {

10
src/lib/mtproto/networker.ts

@ -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);

4
src/lib/storage.ts

@ -196,4 +196,8 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
} }
})); }));
} }
public deleteDatabase() {
return IDBStorage.deleteDatabase();
}
} }

5
src/scss/partials/pages/_pages.scss

@ -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…
Cancel
Save