mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Inline the old _load_entities code
This commit is contained in:
parent
e84c9847c5
commit
6d004601d0
|
@ -301,7 +301,7 @@ class UpdateMethods(UserMethods):
|
|||
conv._on_read(ev)
|
||||
|
||||
if conv._custom:
|
||||
await conv._check_custom(built, channel_id, pts_date)
|
||||
await conv._check_custom(built)
|
||||
|
||||
for builder, callback in self._event_builders:
|
||||
event = built[type(builder)]
|
||||
|
@ -427,7 +427,6 @@ class EventBuilderDict:
|
|||
if isinstance(event, EventCommon):
|
||||
event.original_update = self.update
|
||||
event._set_client(self.client)
|
||||
event._load_entities()
|
||||
elif event:
|
||||
event._client = self.client
|
||||
|
||||
|
|
|
@ -103,9 +103,9 @@ class CallbackQuery(EventBuilder):
|
|||
self._message = None
|
||||
self._answered = False
|
||||
|
||||
def _load_entities(self):
|
||||
def _set_client(self, client):
|
||||
super()._set_client(client)
|
||||
self._sender, self._input_sender = self._get_entity_pair(self.sender_id)
|
||||
return super()._load_entities() and self._input_sender is not None
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
|
|
|
@ -138,8 +138,6 @@ class EventCommon(ChatGetter, abc.ABC):
|
|||
self._client = None
|
||||
self._chat_peer = chat_peer
|
||||
self._message_id = msg_id
|
||||
self._input_chat = None
|
||||
self._chat = None
|
||||
self._broadcast = broadcast
|
||||
self.original_update = None
|
||||
|
||||
|
@ -148,6 +146,10 @@ class EventCommon(ChatGetter, abc.ABC):
|
|||
Setter so subclasses can act accordingly when the client is set.
|
||||
"""
|
||||
self._client = client
|
||||
if self._chat_peer:
|
||||
self._chat, self._input_chat = self._get_entity_pair(self.chat_id)
|
||||
else:
|
||||
self._chat = self._input_chat = None
|
||||
|
||||
def _get_entity_pair(self, entity_id):
|
||||
"""
|
||||
|
@ -164,17 +166,6 @@ class EventCommon(ChatGetter, abc.ABC):
|
|||
|
||||
return entity, input_entity
|
||||
|
||||
def _load_entities(self):
|
||||
"""
|
||||
Must load all the entities it needs from cache, and
|
||||
return ``False`` if it could not find all of them.
|
||||
"""
|
||||
if not self._chat_peer:
|
||||
return True # Nothing to load (e.g. MessageDeleted)
|
||||
|
||||
self._chat, self._input_chat = self._get_entity_pair(self.chat_id)
|
||||
return self._input_chat is not None
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
"""
|
||||
|
|
|
@ -87,9 +87,9 @@ class InlineQuery(EventBuilder):
|
|||
self._input_sender = None
|
||||
self._sender = None
|
||||
|
||||
def _load_entities(self):
|
||||
def _set_client(self, client):
|
||||
super()._set_client(client)
|
||||
self._sender, self._input_sender = self._get_entity_pair(self.sender_id)
|
||||
return super()._load_entities() and self._input_sender is not None
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
|
|
|
@ -204,31 +204,19 @@ class NewMessage(EventBuilder):
|
|||
|
||||
def _set_client(self, client):
|
||||
super()._set_client(client)
|
||||
self.message._finish_init(client, self._entities, None)
|
||||
self.__dict__['_init'] = True # No new attributes can be set
|
||||
|
||||
def _load_entities(self):
|
||||
m = self.message
|
||||
m._finish_init(client, self._entities, None)
|
||||
|
||||
# TODO Duplicated work here
|
||||
m._chat, m._input_chat = self._get_entity_pair(m.chat_id)
|
||||
m._sender, m._input_sender = self._get_entity_pair(m.sender_id)
|
||||
m._via_bot, m._via_input_bot = self._get_entity_pair(m.via_bot_id)
|
||||
if not m.forward:
|
||||
forward_ok = True
|
||||
else:
|
||||
if m.forward:
|
||||
f = m.forward
|
||||
f._chat, f._input_chat = self._get_entity_pair(f.chat_id)
|
||||
f._sender, f._input_sender = self._get_entity_pair(f.sender_id)
|
||||
forward_ok = (
|
||||
(not f.chat_id or f._input_chat is not None)
|
||||
and (not f.sender_id or f._input_sender is not None)
|
||||
)
|
||||
|
||||
return (
|
||||
m._input_chat is not None
|
||||
and (not m.sender_id or m._input_sender is not None)
|
||||
and (not m.via_bot_id or m._via_input_bot is not None)
|
||||
and forward_ok
|
||||
)
|
||||
self.__dict__['_init'] = True # No new attributes can be set
|
||||
|
||||
def __getattr__(self, item):
|
||||
if item in self.__dict__:
|
||||
|
|
|
@ -184,10 +184,7 @@ class UserUpdate(EventBuilder):
|
|||
self._chat_peer = types.PeerChannel(self._chat_peer)
|
||||
|
||||
super()._set_client(client)
|
||||
|
||||
def _load_entities(self):
|
||||
self._sender, self._input_sender = self._get_entity_pair(self.sender_id)
|
||||
return super()._load_entities() and self._input_sender is not None
|
||||
self._sender, self._input_sender = self._get_entity_pair(self._sender_id)
|
||||
|
||||
@property
|
||||
def user(self):
|
||||
|
|
|
@ -294,14 +294,12 @@ class Conversation(ChatGetter):
|
|||
self._custom[counter] = (event, future)
|
||||
return await result()
|
||||
|
||||
async def _check_custom(self, built, channel_id, pts_date):
|
||||
async def _check_custom(self, built):
|
||||
for i, (ev, fut) in self._custom.items():
|
||||
ev_type = type(ev)
|
||||
if built[ev_type] and ev.filter(built[ev_type]):
|
||||
if isinstance(ev, EventCommon) and not ev._load_entities():
|
||||
await ev._get_difference(channel_id, pts_date)
|
||||
|
||||
fut.set_result(built[ev_type])
|
||||
inst = built[ev_type]
|
||||
if inst and ev.filter(inst):
|
||||
fut.set_result(inst)
|
||||
|
||||
def _on_new_message(self, response):
|
||||
response = response.message
|
||||
|
|
Loading…
Reference in New Issue
Block a user