Use the new client.iter_dialogs() in client.get_input_entity()

This commit is contained in:
Lonami Exo 2018-03-08 11:48:59 +01:00
parent 5673866553
commit 3d49f740df

View File

@ -2347,38 +2347,14 @@ class TelegramClient(TelegramBareClient):
# Look in the dialogs with the hope to find it.
mark = not isinstance(peer, int) or peer < 0
target_id = utils.get_peer_id(peer)
req = GetDialogsRequest(
offset_date=None,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=100
)
while True:
result = self(req)
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)
if mark:
for dialog in self.iter_dialogs():
if utils.get_peer_id(dialog.entity) == target_id:
return utils.get_input_peer(dialog.entity)
else:
for dialog in self.iter_dialogs():
if dialog.entity.id == target_id:
return utils.get_input_peer(dialog.entity)
raise TypeError(
'Could not find the input entity corresponding to "{}". '