Make Message.edit respect preview and buttons

This commit is contained in:
Lonami Exo 2019-01-12 12:45:37 +01:00
parent ae4d4ba3ef
commit d31aaa5d0d
2 changed files with 24 additions and 0 deletions

View File

@ -235,6 +235,12 @@ class CallbackQuery(EventBuilder):
Returns the edited :tl:`Message`.
This method also creates a task to `answer` the callback.
.. note::
This method won't respect the previous message unlike
`Message.edit <telethon.tl.custom.message.Message.edit>`,
since the message object is normally not present.
"""
self._client.loop.create_task(self.answer())
return await self._client.edit_message(

View File

@ -628,10 +628,28 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
Returns ``None`` if the message was incoming,
or the edited `Message` otherwise.
.. note::
This is different from `client.edit_message
<telethon.client.messages.MessageMethods.edit_message>`
and **will respect** the previous state of the message.
For example, if the message didn't have a link preview,
the edit won't add one by default, and you should force
it by setting it to ``True`` if you want it.
This is generally the most desired and convenient behaviour,
and will work for link previews and message buttons.
"""
if self.fwd_from or not self.out:
return None # We assume self.out was patched for our chat
if 'link_preview' not in kwargs:
kwargs['link_preview'] = bool(self.web_preview)
if 'buttons' not in kwargs:
kwargs['buttons'] = self.buttons
return await self._client.edit_message(
await self.get_input_chat(), self.id,
*args, **kwargs