Skip to content

Commit

Permalink
chore: refactor telegram api
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Dec 27, 2024
1 parent bd279d1 commit f648984
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/api/telegram/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class TelegramClientApi {
#client;
#events;
#listeners = {};
#authenticated;
#authenticated = true;

constructor ( { apiId, apiHash, session, deviceModel, appVersion, connectionRetries = Infinity, logLevel, connect, ...options } = {} ) {
this.#activityManager = new ActivityManager( {
Expand Down Expand Up @@ -176,7 +176,13 @@ export default class TelegramClientApi {
[ method ]( ...args ) // eslint-disable-line no-unexpected-multiline
.then( data => result( 200, data ) )
.catch( e => {
if ( e.code === 401 ) this.#authenticated = false;

// session terminated
if ( e.code === 401 ) {
this.#authenticated = false;

this.#events.emit( "signout" );
}

return result.catch( e, {
"log": false,
Expand Down

0 comments on commit f648984

Please sign in to comment.