diff --git a/telethon/events/chataction.py b/telethon/events/chataction.py index cbacba82..c6fcb374 100644 --- a/telethon/events/chataction.py +++ b/telethon/events/chataction.py @@ -1,6 +1,6 @@ from .common import EventBuilder, EventCommon, name_inner_event from .. import utils -from ..tl import types, functions +from ..tl import types, functions, custom @name_inner_event @@ -158,6 +158,12 @@ class ChatAction(EventBuilder): self.new_title = new_title self.unpin = unpin + def _set_client(self, client): + super()._set_client(client) + if self.action_message: + self.action_message = custom.Message( + client, self.action_message, self._entities, None) + def respond(self, *args, **kwargs): """ Responds to the chat action message (not as a reply). Shorthand for diff --git a/telethon/events/common.py b/telethon/events/common.py index a7c5db91..e5ecd60f 100644 --- a/telethon/events/common.py +++ b/telethon/events/common.py @@ -103,6 +103,12 @@ class EventCommon(abc.ABC): ) self.is_channel = isinstance(chat_peer, types.PeerChannel) + def _set_client(self, client): + """ + Setter so subclasses can act accordingly when the client is set. + """ + self._client = client + def _get_entity(self, msg_id, entity_id, chat=None): """ Helper function to call :tl:`GetMessages` on the give msg_id and diff --git a/telethon/events/messageread.py b/telethon/events/messageread.py index 16db40bb..3edd8a7f 100644 --- a/telethon/events/messageread.py +++ b/telethon/events/messageread.py @@ -100,16 +100,9 @@ class MessageRead(EventBuilder): chat = self.input_chat if not chat: self._messages = [] - elif isinstance(chat, types.InputPeerChannel): - self._messages =\ - self._client(functions.channels.GetMessagesRequest( - chat, self._message_ids - )).messages else: - self._messages =\ - self._client(functions.messages.GetMessagesRequest( - self._message_ids - )).messages + self._messages = self._client.get_messages( + chat, ids=self._message_ids) return self._messages diff --git a/telethon/events/newmessage.py b/telethon/events/newmessage.py index 082c9737..09b27e7b 100644 --- a/telethon/events/newmessage.py +++ b/telethon/events/newmessage.py @@ -3,7 +3,7 @@ import re from .common import EventBuilder, EventCommon, name_inner_event from .. import utils from ..extensions import markdown -from ..tl import types, functions +from ..tl import types, functions, custom @name_inner_event @@ -154,6 +154,11 @@ class NewMessage(EventBuilder): self.is_reply = bool(message.reply_to_msg_id) self._reply_message = None + def _set_client(self, client): + super()._set_client(client) + self.message = custom.Message( + client, self.message, self._entities, None) + def respond(self, *args, **kwargs): """ Responds to the message (not as a reply). Shorthand for diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 38f45d40..2378c104 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -2416,7 +2416,7 @@ class TelegramClient(TelegramBareClient): for builder, callback in self._event_builders: event = builder.build(update) if event: - event._client = self + event._set_client(self) event.original_update = update try: callback(event)