From 48c8837f19ca4e37da3f932e6f95f4a661bb3d60 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 8 Oct 2017 16:25:50 +0200 Subject: [PATCH] Don't look on all dialogs on .get_entity miss --- telethon/telegram_client.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index bdaa41d8..66ea5ea3 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -956,9 +956,17 @@ class TelegramClient(TelegramBareClient): ) if self.session.save_entities: - # Not found, look in the dialogs (this will save the users) - self.get_dialogs(limit=None) - + # Not found, look in the latest dialogs. + # This is useful if for instance someone just sent a message but + # the updates didn't specify who, as this person or chat should + # be in the latest dialogs. + self(GetDialogsRequest( + offset_date=None, + offset_id=0, + offset_peer=InputPeerEmpty(), + limit=0, + exclude_pinned=True + )) try: return self.session.entities.get_input_entity(peer) except KeyError: