mtcute/packages/client/src/methods/users/get-me.ts
teidesu ec736f8590 some changes
i've been wanting to name a commit like this for my entire life, lol. seriously though, a lot has changed:
 - extracted TL-related stuff to `@mtcute/tl-utils` and `@mtcute/tl-runtime`, rewrote codegen in TS
 - updated to layer 134, moved to int64 identifiers
 - rewritten networking (mtproto), rewritten updates handling
 - *lots* of refactoring

 still a very early version though, there are a lot of improvements to be made, but at least it runs, lol

 also tl-reference will not be updated anytime soon because i want to rewrite it
2021-11-23 00:03:59 +03:00

36 lines
1 KiB
TypeScript

import { TelegramClient } from '../../client'
import { User } from '../../types'
import { assertTypeIs } from '../../utils/type-assertion'
/**
* Get currently authorized user's full information
*
* @internal
*/
export function getMe(this: TelegramClient): Promise<User> {
return this.call({
_: 'users.getUsers',
id: [
{
_: 'inputUserSelf',
},
],
}).then(async ([user]) => {
assertTypeIs('getMe (@ users.getUsers)', user, 'user')
if (this._userId !== user.id) {
// there is such possibility, e.g. when
// using a string session without `self`,
// or logging out and re-logging in
// we need to update the fields accordingly,
// and force-save the session
this._userId = user.id
this._isBot = !!user.bot
await this._saveStorage()
}
this._selfUsername = user.username ?? null
return new User(this, user)
})
}