mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 19:00:21 +03:00
Call .get_dialogs only once on entity not found
This commit is contained in:
parent
81944262fb
commit
1ff5826c26
|
@ -192,6 +192,9 @@ class TelegramClient(TelegramBareClient):
|
||||||
# Sometimes we need to know who we are, cache the self peer
|
# Sometimes we need to know who we are, cache the self peer
|
||||||
self._self_input_peer = None
|
self._self_input_peer = None
|
||||||
|
|
||||||
|
# Don't call .get_dialogs() every time a .get_entity() fails
|
||||||
|
self._called_get_dialogs = False
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
# region Telegram requests functions
|
# region Telegram requests functions
|
||||||
|
@ -2401,16 +2404,18 @@ class TelegramClient(TelegramBareClient):
|
||||||
# Add the mark to the peers if the user passed a Peer (not an int),
|
# Add the mark to the peers if the user passed a Peer (not an int),
|
||||||
# or said ID is negative. If it's negative it's been marked already.
|
# or said ID is negative. If it's negative it's been marked already.
|
||||||
# Look in the dialogs with the hope to find it.
|
# Look in the dialogs with the hope to find it.
|
||||||
mark = not isinstance(peer, int) or peer < 0
|
if not self._called_get_dialogs:
|
||||||
target_id = utils.get_peer_id(peer)
|
self._called_get_dialogs = True
|
||||||
if mark:
|
mark = not isinstance(peer, int) or peer < 0
|
||||||
for dialog in self.iter_dialogs():
|
target_id = utils.get_peer_id(peer)
|
||||||
if utils.get_peer_id(dialog.entity) == target_id:
|
if mark:
|
||||||
return utils.get_input_peer(dialog.entity)
|
for dialog in self.get_dialogs(100):
|
||||||
else:
|
if utils.get_peer_id(dialog.entity) == target_id:
|
||||||
for dialog in self.iter_dialogs():
|
return utils.get_input_peer(dialog.entity)
|
||||||
if dialog.entity.id == target_id:
|
else:
|
||||||
return utils.get_input_peer(dialog.entity)
|
for dialog in self.get_dialogs(100):
|
||||||
|
if dialog.entity.id == target_id:
|
||||||
|
return utils.get_input_peer(dialog.entity)
|
||||||
|
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
'Could not find the input entity corresponding to "{}". '
|
'Could not find the input entity corresponding to "{}". '
|
||||||
|
|
Loading…
Reference in New Issue
Block a user