mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 09:53:45 +03:00
Use the new client.iter_dialogs() in client.get_input_entity()
This commit is contained in:
parent
5673866553
commit
3d49f740df
|
@ -2347,38 +2347,14 @@ class TelegramClient(TelegramBareClient):
|
||||||
# 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
|
mark = not isinstance(peer, int) or peer < 0
|
||||||
target_id = utils.get_peer_id(peer)
|
target_id = utils.get_peer_id(peer)
|
||||||
req = GetDialogsRequest(
|
if mark:
|
||||||
offset_date=None,
|
for dialog in self.iter_dialogs():
|
||||||
offset_id=0,
|
if utils.get_peer_id(dialog.entity) == target_id:
|
||||||
offset_peer=InputPeerEmpty(),
|
return utils.get_input_peer(dialog.entity)
|
||||||
limit=100
|
else:
|
||||||
)
|
for dialog in self.iter_dialogs():
|
||||||
while True:
|
if dialog.entity.id == target_id:
|
||||||
result = self(req)
|
return utils.get_input_peer(dialog.entity)
|
||||||
entities = {}
|
|
||||||
if mark:
|
|
||||||
for x in itertools.chain(result.users, result.chats):
|
|
||||||
x_id = utils.get_peer_id(x)
|
|
||||||
if x_id == target_id:
|
|
||||||
return utils.get_input_peer(x)
|
|
||||||
else:
|
|
||||||
entities[x_id] = x
|
|
||||||
else:
|
|
||||||
for x in itertools.chain(result.users, result.chats):
|
|
||||||
if x.id == target_id:
|
|
||||||
return utils.get_input_peer(x)
|
|
||||||
else:
|
|
||||||
entities[utils.get_peer_id(x)] = x
|
|
||||||
|
|
||||||
if len(result.dialogs) < req.limit:
|
|
||||||
break
|
|
||||||
|
|
||||||
req.offset_id = result.messages[-1].id
|
|
||||||
req.offset_date = result.messages[-1].date
|
|
||||||
req.offset_peer = entities[utils.get_peer_id(
|
|
||||||
result.dialogs[-1].peer
|
|
||||||
)]
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
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