mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 19:16:43 +00:00
Fix UserUpdate in chats
This commit is contained in:
parent
9db9db1ade
commit
0239852cc7
@ -92,11 +92,13 @@ class UserUpdate(EventBuilder):
|
|||||||
``True`` if what's being uploaded (selected) is a contact.
|
``True`` if what's being uploaded (selected) is a contact.
|
||||||
"""
|
"""
|
||||||
def __init__(self, user_id, *, status=None, chat_id=None, typing=None):
|
def __init__(self, user_id, *, status=None, chat_id=None, typing=None):
|
||||||
|
# TODO Now we need to use the user_id!
|
||||||
|
if chat_id is None:
|
||||||
super().__init__(types.PeerUser(user_id))
|
super().__init__(types.PeerUser(user_id))
|
||||||
|
else:
|
||||||
# TODO This should be passed to init, not here
|
# Temporarily set the chat_peer to the ID until ._set_client.
|
||||||
# But we need to know the type beforehand
|
# We need the client to actually figure out its type.
|
||||||
self.chat_id = chat_id
|
super().__init__(chat_id)
|
||||||
|
|
||||||
self.online = None if status is None else \
|
self.online = None if status is None else \
|
||||||
isinstance(status, types.UserStatusOnline)
|
isinstance(status, types.UserStatusOnline)
|
||||||
@ -161,6 +163,24 @@ class UserUpdate(EventBuilder):
|
|||||||
elif isinstance(typing, types.SendMessageUploadVideoAction):
|
elif isinstance(typing, types.SendMessageUploadVideoAction):
|
||||||
self.uploading = self.video = True
|
self.uploading = self.video = True
|
||||||
|
|
||||||
|
def _set_client(self, client):
|
||||||
|
if isinstance(self._chat_peer, int):
|
||||||
|
try:
|
||||||
|
chat = client.session.get_input_entity(self._chat_peer)
|
||||||
|
if isinstance(chat, types.InputPeerChat):
|
||||||
|
self._chat_peer = types.PeerChat(self._chat_peer)
|
||||||
|
elif isinstance(chat, types.InputPeerChannel):
|
||||||
|
self._chat_peer = types.PeerChannel(self._chat_peer)
|
||||||
|
else:
|
||||||
|
# Should not happen
|
||||||
|
self._chat_peer = types.PeerUser(self._chat_peer)
|
||||||
|
except ValueError:
|
||||||
|
# Hope for the best. We don't know where this event
|
||||||
|
# occurred but it was most likely in a channel.
|
||||||
|
self._chat_peer = types.PeerChannel(self._chat_peer)
|
||||||
|
|
||||||
|
super()._set_client(client)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user(self):
|
def user(self):
|
||||||
"""Alias for `chat` (conversation)."""
|
"""Alias for `chat` (conversation)."""
|
||||||
|
Loading…
Reference in New Issue
Block a user