mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Correctly emulate old to_id behaviour
This commit is contained in:
parent
e24c49f5be
commit
4321153b06
|
@ -616,15 +616,8 @@ class EventBuilderDict:
|
|||
try:
|
||||
return self.__dict__[builder]
|
||||
except KeyError:
|
||||
# Updates may arrive before login (like updateLoginToken) and we
|
||||
# won't have our self ID yet (anyway only new messages need it).
|
||||
self_id = (
|
||||
self.client._self_input_peer.user_id
|
||||
if self.client._self_input_peer
|
||||
else None
|
||||
)
|
||||
event = self.__dict__[builder] = builder.build(
|
||||
self.update, self.others, self_id)
|
||||
self.update, self.others, self.client._self_id)
|
||||
|
||||
if isinstance(event, EventCommon):
|
||||
event.original_update = self.update
|
||||
|
|
|
@ -164,6 +164,16 @@ class UserMethods:
|
|||
except errors.UnauthorizedError:
|
||||
return None
|
||||
|
||||
@property
|
||||
def _self_id(self: 'TelegramClient') -> typing.Optional[int]:
|
||||
"""
|
||||
Returns the ID of the logged-in user, if known.
|
||||
|
||||
This property is used in every update, and some like `updateLoginToken`
|
||||
occur prior to login, so it gracefully handles when no ID is known yet.
|
||||
"""
|
||||
return self._self_input_peer.user_id if self._self_input_peer else None
|
||||
|
||||
async def is_bot(self: 'TelegramClient') -> bool:
|
||||
"""
|
||||
Return `True` if the signed-in user is a bot, `False` otherwise.
|
||||
|
|
|
@ -608,9 +608,14 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
|||
@property
|
||||
def to_id(self):
|
||||
"""
|
||||
Alias for ``.peer_id``. Telegram renamed the field, and this property
|
||||
exists to avoid breaking code.
|
||||
Returns the peer to which this message was sent to. This used to exist
|
||||
to infer the ``.peer_id``.
|
||||
"""
|
||||
# If the client wasn't set we can't emulate the behaviour correctly,
|
||||
# so as a best-effort simply return the chat peer.
|
||||
if self._client and not self.out and self.is_private:
|
||||
return types.PeerUser(self._client._self_id)
|
||||
|
||||
return self.peer_id
|
||||
|
||||
# endregion Public Properties
|
||||
|
|
Loading…
Reference in New Issue
Block a user