Browse Source

Fix login state with different base dc id

Fix password input height
Removed focus monkey on auth code page
master
Eduard Kuzmenko 4 years ago
parent
commit
eb27ab31e3
  1. 4
      src/lib/appManagers/appDialogsManager.ts
  2. 4
      src/lib/appManagers/appStateManager.ts
  3. 49
      src/lib/mtproto/apiManager.ts
  4. 5
      src/lib/mtproto/mtproto_config.ts
  5. 4
      src/lib/mtproto/mtprotoworker.ts
  6. 10
      src/lib/mtproto/passwordManager.ts
  7. 6
      src/lib/rootScope.ts
  8. 14
      src/pages/pageAuthCode.ts
  9. 4
      src/pages/pagePassword.ts
  10. 4
      src/pages/pageSignQR.ts
  11. 4
      src/pages/pageSignUp.ts
  12. 1
      src/scss/partials/pages/_password.scss

4
src/lib/appManagers/appDialogsManager.ts

@ -110,7 +110,7 @@ class ConnectionStatusComponent { @@ -110,7 +110,7 @@ class ConnectionStatusComponent {
let setFirstConnectionTimeout = window.setTimeout(setConnectionStatus, 2e3);
let bool = true;
/* let bool = true;
document.addEventListener('dblclick', () => {
rootScope.broadcast('connection_status_change', {
dcID: 2,
@ -121,7 +121,7 @@ class ConnectionStatusComponent { @@ -121,7 +121,7 @@ class ConnectionStatusComponent {
online: bool = !bool,
_: "networkerStatus"
});
});
}); */
}
private setStatusText = (text: string) => {

4
src/lib/appManagers/appStateManager.ts

@ -88,10 +88,10 @@ export class AppStateManager extends EventListenerBase<{ @@ -88,10 +88,10 @@ export class AppStateManager extends EventListenerBase<{
//return resolve();
if(auth?.id) {
if(auth) {
// ! Warning ! DON'T delete this
this.state.authState = {_: 'authStateSignedIn'};
rootScope.broadcast('user_auth', {id: auth.id});
rootScope.broadcast('user_auth', auth);
} else if(!this.state.authState) {
this.state.authState = {_: 'authStateSignIn'};
}

49
src/lib/mtproto/apiManager.ts

@ -54,7 +54,7 @@ export class ApiManager { @@ -54,7 +54,7 @@ export class ApiManager {
private gettingNetworkers: {[dcIDAndType: string]: Promise<MTPNetworker>} = {};
public baseDcID = 0;
public telegramMeNotified = false;
//public telegramMeNotified = false;
private log: ReturnType<typeof logger> = logger('API');
@ -72,30 +72,32 @@ export class ApiManager { @@ -72,30 +72,32 @@ export class ApiManager {
}); */
}
public telegramMeNotify(newValue: boolean) {
/* public telegramMeNotify(newValue: boolean) {
if(this.telegramMeNotified !== newValue) {
this.telegramMeNotified = newValue;
//telegramMeWebService.setAuthorized(this.telegramMeNotified);
}
}
} */
// mtpSetUserAuth
public setUserAuth(userAuth: {id: number}) {
var fullUserAuth = Object.assign({dcID: this.baseDcID}, userAuth);
public setUserAuth(userID: number) {
AppStorage.set({
dc: this.baseDcID,
user_auth: fullUserAuth
user_auth: userID
});
this.telegramMeNotify(true);
//this.telegramMeNotify(true);
/// #if !MTPROTO_WORKER
rootScope.broadcast('user_auth', fullUserAuth);
rootScope.broadcast('user_auth', userID);
/// #endif
}
public setBaseDcID(dcID: number) {
this.baseDcID = dcID;
AppStorage.set({
dc: this.baseDcID
});
}
// mtpLogOut
@ -124,7 +126,7 @@ export class ApiManager { @@ -124,7 +126,7 @@ export class ApiManager {
error.handled = true;
}).finally(() => {
this.baseDcID = 0;
this.telegramMeNotify(false);
//this.telegramMeNotify(false);
AppStorage.clear();
})/* .then(() => {
location.pathname = '/';
@ -284,11 +286,11 @@ export class ApiManager { @@ -284,11 +286,11 @@ export class ApiManager {
}
};
var dcID: number;
let dcID: number;
var cachedNetworker: MTPNetworker;
var stack = (new Error()).stack || 'empty stack';
var performRequest = (networker: MTPNetworker) => {
let cachedNetworker: MTPNetworker;
let stack = (new Error()).stack || 'empty stack';
const performRequest = (networker: MTPNetworker) => {
if(afterMessageIDTemp) {
options.afterMessageID = this.afterMessageTempIDs[afterMessageIDTemp];
}
@ -304,17 +306,20 @@ export class ApiManager { @@ -304,17 +306,20 @@ export class ApiManager {
}
if(error.code == 401 && this.baseDcID == dcID) {
AppStorage.remove('dc', 'user_auth');
this.telegramMeNotify(false);
if(error.type != 'SESSION_PASSWORD_NEEDED') {
AppStorage.remove('dc', 'user_auth'); // ! возможно тут вообще не нужно это делать, но нужно проверить случай с USER_DEACTIVATED (https://core.telegram.org/api/errors)
//this.telegramMeNotify(false);
}
rejectPromise(error);
} else if(error.code == 401 && this.baseDcID && dcID != this.baseDcID) {
if(this.cachedExportPromise[dcID] === undefined) {
let promise = new Promise((exportResolve, exportReject) => {
const promise = new Promise((exportResolve, exportReject) => {
this.invokeApi('auth.exportAuthorization', {dc_id: dcID}, {noErrorBox: true}).then((exportedAuth) => {
this.invokeApi('auth.importAuthorization', {
id: exportedAuth.id,
bytes: exportedAuth.bytes
}, {dcID: dcID, noErrorBox: true}).then(exportResolve, exportReject);
}, {dcID, noErrorBox: true}).then(exportResolve, exportReject);
}, exportReject);
});
@ -326,12 +331,12 @@ export class ApiManager { @@ -326,12 +331,12 @@ export class ApiManager {
this.invokeApi(method, params, options).then(deferred.resolve, rejectPromise);
}, rejectPromise);
} else if(error.code == 303) {
var newDcID = +error.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_|USER_MIGRATE_)(\d+)/)[2];
const newDcID = +error.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_|USER_MIGRATE_)(\d+)/)[2];
if(newDcID != dcID) {
if(options.dcID) {
options.dcID = newDcID;
} else {
AppStorage.set({dc: this.baseDcID = newDcID});
this.setBaseDcID(newDcID);
}
this.getNetworker(newDcID, options).then((networker) => {
@ -339,7 +344,7 @@ export class ApiManager { @@ -339,7 +344,7 @@ export class ApiManager {
}, rejectPromise);
}
} else if(!options.rawError && error.code == 420) {
var waitTime = +error.type.match(/^FLOOD_WAIT_(\d+)/)[1] || 10;
const waitTime = +error.type.match(/^FLOOD_WAIT_(\d+)/)[1] || 10;
if(waitTime > (options.floodMaxTimeout !== undefined ? options.floodMaxTimeout : 60)) {
return rejectPromise(error);
@ -349,7 +354,7 @@ export class ApiManager { @@ -349,7 +354,7 @@ export class ApiManager {
performRequest(cachedNetworker);
}, waitTime/* (waitTime + 5) */ * 1000); // 03.02.2020
} else if(!options.rawError && (error.code == 500 || error.type == 'MSG_WAIT_FAILED')) {
var now = Date.now();
const now = Date.now();
if(options.stopTime) {
if(now >= options.stopTime) {
return rejectPromise(error);

5
src/lib/mtproto/mtproto_config.ts

@ -1,7 +1,4 @@ @@ -1,7 +1,4 @@
export type UserAuth = {
dcID: number,
id: number
};
export type UserAuth = number;
/*

4
src/lib/mtproto/mtprotoworker.ts

@ -10,7 +10,7 @@ import webpWorkerController from '../webp/webpWorkerController'; @@ -10,7 +10,7 @@ import webpWorkerController from '../webp/webpWorkerController';
import type { DownloadOptions } from './apiFileManager';
import { ApiError } from './apiManager';
import type { ServiceWorkerTask, ServiceWorkerTaskResponse } from './mtproto.service';
import { MOUNT_CLASS_TO } from './mtproto_config';
import { MOUNT_CLASS_TO, UserAuth } from './mtproto_config';
import type { MTMessage } from './networker';
import referenceDatabase from './referenceDatabase';
@ -230,7 +230,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods { @@ -230,7 +230,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
return this.performTaskWorker('setBaseDcID', dcID);
}
public setUserAuth(userAuth: {id: number}) {
public setUserAuth(userAuth: UserAuth) {
rootScope.broadcast('user_auth', userAuth);
return this.performTaskWorker('setUserAuth', userAuth);
}

10
src/lib/mtproto/passwordManager.ts

@ -4,8 +4,8 @@ import { MOUNT_CLASS_TO } from './mtproto_config'; @@ -4,8 +4,8 @@ import { MOUNT_CLASS_TO } from './mtproto_config';
//import { computeCheck } from "../crypto/srp";
export class PasswordManager {
public getState(options: any = {}): Promise<AccountPassword> {
return apiManager.invokeApi('account.getPassword', {}, options).then((result) => {
public getState(): Promise<AccountPassword> {
return apiManager.invokeApi('account.getPassword').then((result) => {
return result;
});
}
@ -61,15 +61,15 @@ export class PasswordManager { @@ -61,15 +61,15 @@ export class PasswordManager {
});
}
public requestRecovery(options: any = {}) {
/* public requestRecovery(options: any = {}) {
return apiManager.invokeApi('auth.requestPasswordRecovery', {}, options);
}
public recover(code: any, options: any = {}) {
return apiManager.invokeApi('auth.recoverPassword', {
code: code
code
}, options);
}
} */
}
const passwordManager = new PasswordManager();

6
src/lib/rootScope.ts

@ -4,11 +4,11 @@ import type { AppMessagesManager, Dialog } from "./appManagers/appMessagesManage @@ -4,11 +4,11 @@ import type { AppMessagesManager, Dialog } from "./appManagers/appMessagesManage
import type { Poll, PollResults } from "./appManagers/appPollsManager";
import type { MyDialogFilter } from "./storages/filters";
import type { ConnectionStatusChange } from "../types";
import { MOUNT_CLASS_TO } from "./mtproto/mtproto_config";
import { MOUNT_CLASS_TO, UserAuth } from "./mtproto/mtproto_config";
type BroadcastEvents = {
'user_update': number,
'user_auth': {dcID?: number, id: number},
'user_auth': UserAuth,
'peer_changed': number,
'peer_pinned_message': number,
@ -79,7 +79,7 @@ class RootScope { @@ -79,7 +79,7 @@ class RootScope {
constructor() {
this.on('user_auth', (e) => {
this.myID = e.detail.id;
this.myID = e.detail;
});
this.on('connection_status_change', (e) => {

14
src/pages/pageAuthCode.ts

@ -126,14 +126,12 @@ let onFirstMount = (): Promise<any> => { @@ -126,14 +126,12 @@ let onFirstMount = (): Promise<any> => {
//console.log('invoking auth.signIn with params:', params);
apiManager.invokeApi('auth.signIn', params, {ignoreErrors: true})
.then((response: any) => {
.then((response) => {
//console.log('auth.signIn response:', response);
switch(response._) {
case 'auth.authorization':
apiManager.setUserAuth({
id: response.user.id
});
apiManager.setUserAuth(response.user.id);
pageIm.mount();
cleanup();
@ -148,9 +146,9 @@ let onFirstMount = (): Promise<any> => { @@ -148,9 +146,9 @@ let onFirstMount = (): Promise<any> => {
cleanup();
break;
default:
/* default:
codeInput.innerText = response._;
break;
break; */
}
}).catch(async(err) => {
switch(err.type) {
@ -242,9 +240,9 @@ let onFirstMount = (): Promise<any> => { @@ -242,9 +240,9 @@ let onFirstMount = (): Promise<any> => {
//animation.goToAndStop(length / max * );
};
codeInput.addEventListener('focus', () => {
/* codeInput.addEventListener('focus', () => {
playAnimation(Math.max(codeInput.value.length, 1));
});
}); */
codeInput.addEventListener('blur', () => {
playAnimation(0);

4
src/pages/pagePassword.ts

@ -95,9 +95,7 @@ let onFirstMount = (): Promise<any> => { @@ -95,9 +95,7 @@ let onFirstMount = (): Promise<any> => {
switch(response._) {
case 'auth.authorization':
apiManager.setUserAuth({
id: response.user.id
});
apiManager.setUserAuth(response.user.id);
clearInterval(getStateInterval);
pageIm.mount();

4
src/pages/pageSignQR.ts

@ -61,9 +61,7 @@ let onFirstMount = async() => { @@ -61,9 +61,7 @@ let onFirstMount = async() => {
if(loginToken._ == 'auth.loginTokenSuccess') {
const authorization = loginToken.authorization as any as AuthAuthorization.authAuthorization;
apiManager.setUserAuth({
id: authorization.user.id
});
apiManager.setUserAuth(authorization.user.id);
pageIm.mount();
break;
}

4
src/pages/pageSignUp.ts

@ -85,9 +85,7 @@ let onFirstMount = () => import('../lib/appManagers/appProfileManager').then(imp @@ -85,9 +85,7 @@ let onFirstMount = () => import('../lib/appManagers/appProfileManager').then(imp
switch(response._) {
case 'auth.authorization': // success
apiManager.setUserAuth({ // warning
id: response.user.id
});
apiManager.setUserAuth(response.user.id);
sendAvatar().finally(() => {
pageIm.mount();

1
src/scss/partials/pages/_password.scss

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
.page-password {
#password {
padding-right: 2.5rem;
max-height: 54px;
&[type="password"] {
font-size: 2.25rem;

Loading…
Cancel
Save