Store self user in entity cache

This commit is contained in:
Lonami Exo
2023-04-06 13:58:26 +02:00
parent 97b0ba6707
commit 88bc6a46a6
5 changed files with 16 additions and 23 deletions

View File

@@ -152,20 +152,17 @@ class UserMethods:
me = await client.get_me()
print(me.username)
"""
if input_peer and self._self_input_peer:
return self._self_input_peer
if input_peer and self._mb_entity_cache.self_id:
return self._mb_entity_cache.get(self._mb_entity_cache.self_id)._as_input_peer()
try:
me = (await self(
functions.users.GetUsersRequest([types.InputUserSelf()])))[0]
self._bot = me.bot
if not self._self_input_peer:
self._self_input_peer = utils.get_input_peer(
me, allow_self=False
)
if not self._mb_entity_cache.self_id:
self._mb_entity_cache.set_self_user(me.id, me.bot, me.access_hash)
return self._self_input_peer if input_peer else me
return utils.get_input_peer(me, allow_self=False) if input_peer else me
except errors.UnauthorizedError:
return None
@@ -177,7 +174,7 @@ class UserMethods:
This property is used in every update, and some like `updateLoginToken`
occur prior to login, so it gracefully handles when no ID is known yet.
"""
return self._self_input_peer.user_id if self._self_input_peer else None
return self._mb_entity_cache.self_id
async def is_bot(self: 'TelegramClient') -> bool:
"""
@@ -191,10 +188,10 @@ class UserMethods:
else:
print('Hello')
"""
if self._bot is None:
self._bot = (await self.get_me()).bot
if self._mb_entity_cache.self_id is None:
await self.get_me(input_peer=True)
return self._bot
return self._mb_entity_cache.self_bot
async def is_user_authorized(self: 'TelegramClient') -> bool:
"""