mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-20 20:16:38 +00:00
Return the entire entity from the helper events._get_entity too
This commit is contained in:
parent
7e9d19d727
commit
8ae12fbb70
@ -87,12 +87,15 @@ class _EventCommon(abc.ABC):
|
|||||||
)
|
)
|
||||||
self.is_channel = isinstance(chat_peer, types.PeerChannel)
|
self.is_channel = isinstance(chat_peer, types.PeerChannel)
|
||||||
|
|
||||||
def _get_input_entity(self, msg_id, entity_id, chat=None):
|
def _get_entity(self, msg_id, entity_id, chat=None):
|
||||||
"""
|
"""
|
||||||
Helper function to call GetMessages on the give msg_id and
|
Helper function to call GetMessages on the give msg_id and
|
||||||
return the input entity whose ID is the given entity ID.
|
return the input entity whose ID is the given entity ID.
|
||||||
|
|
||||||
If ``chat`` is present it must be an InputPeer.
|
If ``chat`` is present it must be an InputPeer.
|
||||||
|
|
||||||
|
Returns a tuple of (entity, input_peer) if it was found, or
|
||||||
|
a tuple of (None, None) if it couldn't be.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if isinstance(chat, types.InputPeerChannel):
|
if isinstance(chat, types.InputPeerChannel):
|
||||||
@ -104,15 +107,17 @@ class _EventCommon(abc.ABC):
|
|||||||
functions.messages.GetMessagesRequest([msg_id])
|
functions.messages.GetMessagesRequest([msg_id])
|
||||||
)
|
)
|
||||||
except RPCError:
|
except RPCError:
|
||||||
return
|
return None, None
|
||||||
# TODO This could return a tuple to also have the full entity
|
|
||||||
entity = {
|
entity = {
|
||||||
utils.get_peer_id(x): x for x in itertools.chain(
|
utils.get_peer_id(x): x for x in itertools.chain(
|
||||||
getattr(result, 'chats', []),
|
getattr(result, 'chats', []),
|
||||||
getattr(result, 'users', []))
|
getattr(result, 'users', []))
|
||||||
}.get(entity_id)
|
}.get(entity_id)
|
||||||
if entity:
|
if entity:
|
||||||
return utils.get_input_peer(entity)
|
return entity, utils.get_input_peer(entity)
|
||||||
|
else:
|
||||||
|
return None, None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def input_chat(self):
|
def input_chat(self):
|
||||||
@ -136,7 +141,7 @@ class _EventCommon(abc.ABC):
|
|||||||
# TODO For channels, getDifference? Maybe looking
|
# TODO For channels, getDifference? Maybe looking
|
||||||
# in the dialogs (which is already done) is enough.
|
# in the dialogs (which is already done) is enough.
|
||||||
if self._message_id is not None:
|
if self._message_id is not None:
|
||||||
self._input_chat = self._get_input_entity(
|
self._chat, self._input_chat = self._get_entity(
|
||||||
self._message_id,
|
self._message_id,
|
||||||
utils.get_peer_id(self._chat_peer)
|
utils.get_peer_id(self._chat_peer)
|
||||||
)
|
)
|
||||||
@ -392,7 +397,7 @@ class NewMessage(_EventBuilder):
|
|||||||
)
|
)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
# We can rely on self.input_chat for this
|
# We can rely on self.input_chat for this
|
||||||
self._input_sender = self._get_input_entity(
|
self._sender, self._input_sender = self._get_entity(
|
||||||
self.message.id,
|
self.message.id,
|
||||||
self.message.from_id,
|
self.message.from_id,
|
||||||
chat=self.input_chat
|
chat=self.input_chat
|
||||||
|
Loading…
Reference in New Issue
Block a user