Force fetch sender/chat if only min information was given

This commit is contained in:
Lonami Exo 2019-04-05 21:28:31 +04:00
parent 21a8a50ab9
commit 29b21209bf
2 changed files with 11 additions and 2 deletions

View File

@ -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)

View File

@ -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)