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

4
src/lib/appManagers/appStateManager.ts

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

49
src/lib/mtproto/apiManager.ts

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

5
src/lib/mtproto/mtproto_config.ts

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

4
src/lib/mtproto/mtprotoworker.ts

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

10
src/lib/mtproto/passwordManager.ts

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

6
src/lib/rootScope.ts

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

14
src/pages/pageAuthCode.ts

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

4
src/pages/pagePassword.ts

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

4
src/pages/pageSignQR.ts

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

4
src/pages/pageSignUp.ts

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

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

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

Loading…
Cancel
Save