diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index f93c6b0d..85968968 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -1105,17 +1105,21 @@ class _Message(ChatGetter, SenderGetter): # endregion Private Methods -def _patch(cls): - # Create new types (classes) for all messages to combine `_Message` in them. - # `_Message` comes first so we get its `__init__`. - newtype = type(cls.__name__, (_Message, cls), {}) - setattr(types, cls.__name__, newtype) - # `BinaryReader` directly imports this dictionary, but we're mutating it - # in-place, not replacing it, so it works out to deserialize `newtype`. - alltlobjects.tlobjects[cls.CONSTRUCTOR_ID] = newtype - return newtype +class MessageEmpty(_Message, types.MessageEmpty): + pass -_patch(types.MessageEmpty) -Message = _patch(types.Message) -_patch(types.MessageService) +types.MessageEmpty = MessageEmpty +alltlobjects.tlobjects[MessageEmpty.CONSTRUCTOR_ID] = MessageEmpty + +class MessageService(_Message, types.MessageService): + pass + +types.MessageService = MessageService +alltlobjects.tlobjects[MessageService.CONSTRUCTOR_ID] = MessageService + +class Message(_Message, types.Message): + pass + +types.Message = Message +alltlobjects.tlobjects[Message.CONSTRUCTOR_ID] = Message