@ -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 ) {
/ * p u b l i c t e l e g r a m M e N o t i f y ( n e w V a l u e : b o o l e a n ) {
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 ) {
le t promise = new Promise ( ( exportResolve , exportReject ) = > {
cons t 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 ) ;