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. # 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(
offset_date=None,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=100
)
while True:
result = self(req)
entities = {}
if mark: if mark:
for x in itertools.chain(result.users, result.chats): for dialog in self.iter_dialogs():
x_id = utils.get_peer_id(x) if utils.get_peer_id(dialog.entity) == target_id:
if x_id == target_id: return utils.get_input_peer(dialog.entity)
return utils.get_input_peer(x)
else: else:
entities[x_id] = x for dialog in self.iter_dialogs():
else: if dialog.entity.id == target_id:
for x in itertools.chain(result.users, result.chats): return utils.get_input_peer(dialog.entity)
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 "{}". '