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 ec6ad37 commit bd279d1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/api/telegram/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class TelegramClientApi {
#client;
#events;
#listeners = {};
#authenticated;

constructor ( { apiId, apiHash, session, deviceModel, appVersion, connectionRetries = Infinity, logLevel, connect, ...options } = {} ) {
this.#activityManager = new ActivityManager( {
Expand Down Expand Up @@ -60,6 +61,10 @@ export default class TelegramClientApi {
return this.#client.connected;
}

get isAuthenticated () {
return this.#authenticated;
}

// public
async createSession ( { accountId, phoneCode, password } = {} ) {
if ( !accountId ) {
Expand Down Expand Up @@ -170,10 +175,13 @@ export default class TelegramClientApi {
const res = await this.#client
[ method ]( ...args ) // eslint-disable-line no-unexpected-multiline
.then( data => result( 200, data ) )
.catch( e =>
result.catch( e, {
.catch( e => {
if ( e.code === 401 ) this.#authenticated = false;

return result.catch( e, {
"log": false,
} ) );
} );
} );

this.#activityManager.finishActivity();

Expand Down

0 comments on commit bd279d1

Please sign in to comment.