Skip to content

Commit

Permalink
Merge pull request #435 from KurosawaAngel/feature/edit_media
Browse files Browse the repository at this point in the history
Edit text message to media
  • Loading branch information
Tishka17 authored Nov 6, 2024
2 parents c5e24e4 + c36ea7c commit 33dacdf
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/aiogram_dialog/manager/message_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ def _message_changed(

def _can_edit(self, new_message: NewMessage,
old_message: OldMessage) -> bool:
# we cannot edit message if media appeared or removed
return (
self.had_media(old_message) == self.need_media(new_message) and
not self.had_reply_keyboard(old_message) and
not self.need_reply_keyboard(new_message)
# we cannot edit message if media removed
if self.had_media(old_message) and not self.need_media(new_message):
return False
return not (
self.had_reply_keyboard(old_message) or
self.need_reply_keyboard(new_message)
)

async def show_message(
Expand Down Expand Up @@ -293,7 +294,10 @@ async def edit_message(
self, bot: Bot, new_message: NewMessage, old_message: OldMessage,
) -> Message:
if new_message.media:
if new_message.media.file_id == old_message.media_id:
if (
old_message.media_id is not None and
new_message.media.file_id == old_message.media_id
):
return await self.edit_caption(bot, new_message, old_message)
return await self.edit_media(bot, new_message, old_message)
else:
Expand Down

0 comments on commit 33dacdf

Please sign in to comment.