From 29b21209bf070a5fd65ed569e1bd206b18a01367 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 5 Apr 2019 21:28:31 +0400 Subject: [PATCH] Force fetch sender/chat if only min information was given --- telethon/tl/custom/chatgetter.py | 4 +++- telethon/tl/custom/sendergetter.py | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/telethon/tl/custom/chatgetter.py b/telethon/tl/custom/chatgetter.py index 7fdb79a0..6ada0771 100644 --- a/telethon/tl/custom/chatgetter.py +++ b/telethon/tl/custom/chatgetter.py @@ -29,7 +29,9 @@ class ChatGetter(abc.ABC): Returns `chat`, but will make an API call to find the chat unless it's already cached. """ - if self._chat is None and await self.get_input_chat(): + # See `get_sender` for information about 'min'. + if (self._chat is None or getattr(self._chat, 'min', None))\ + and await self.get_input_chat(): try: self._chat =\ await self._client.get_entity(self._input_chat) diff --git a/telethon/tl/custom/sendergetter.py b/telethon/tl/custom/sendergetter.py index 0f70d3f2..1d27d142 100644 --- a/telethon/tl/custom/sendergetter.py +++ b/telethon/tl/custom/sendergetter.py @@ -26,7 +26,14 @@ class SenderGetter(abc.ABC): Returns `sender`, but will make an API call to find the sender unless it's already cached. """ - if self._sender is None and await self.get_input_sender(): + # ``sender.min`` is present both in :tl:`User` and :tl:`Channel`. + # It's a flag that will be set if only minimal information is + # available (such as display name, but username may be missing), + # in which case we want to force fetch the entire thing because + # the user explicitly called a method. If the user is okay with + # cached information, they may use the property instead. + if (self._sender is None or self._sender.min) \ + and await self.get_input_sender(): try: self._sender =\ await self._client.get_entity(self._input_sender)