mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Reuse code for _get_entity_pair
Less error-prone, improved the function flow for all callers, and removed some duplicate work.
This commit is contained in:
@@ -147,25 +147,11 @@ class EventCommon(ChatGetter, abc.ABC):
|
||||
"""
|
||||
self._client = client
|
||||
if self._chat_peer:
|
||||
self._chat, self._input_chat = self._get_entity_pair(self.chat_id)
|
||||
self._chat, self._input_chat = utils._get_entity_pair(
|
||||
self.chat_id, self._entities, client._entity_cache)
|
||||
else:
|
||||
self._chat = self._input_chat = None
|
||||
|
||||
def _get_entity_pair(self, entity_id):
|
||||
"""
|
||||
Returns ``(entity, input_entity)`` for the given entity ID.
|
||||
"""
|
||||
entity = self._entities.get(entity_id)
|
||||
try:
|
||||
input_entity = utils.get_input_peer(entity)
|
||||
except TypeError:
|
||||
try:
|
||||
input_entity = self._client._entity_cache[entity_id]
|
||||
except KeyError:
|
||||
input_entity = None
|
||||
|
||||
return entity, input_entity
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user