From 6d2d8474482142894f1a82daa516f876873b7279 Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:47:30 +0500 Subject: [PATCH 1/4] edit text to media --- src/aiogram_dialog/manager/message_manager.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/aiogram_dialog/manager/message_manager.py b/src/aiogram_dialog/manager/message_manager.py index 773c9cb2..a48d2da0 100644 --- a/src/aiogram_dialog/manager/message_manager.py +++ b/src/aiogram_dialog/manager/message_manager.py @@ -130,13 +130,12 @@ def _message_changed( return False - def _can_edit(self, new_message: NewMessage, - old_message: OldMessage) -> bool: + 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) + not (self.had_media(old_message) and not self.need_media(new_message)) + and not self.had_reply_keyboard(old_message) + and not self.need_reply_keyboard(new_message) ) async def show_message( @@ -293,7 +292,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: From fbacbf9635dd8f62decdef647387df91bb0f3182 Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:04:05 +0500 Subject: [PATCH 2/4] fix flake --- src/aiogram_dialog/manager/message_manager.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/aiogram_dialog/manager/message_manager.py b/src/aiogram_dialog/manager/message_manager.py index a48d2da0..c86879e4 100644 --- a/src/aiogram_dialog/manager/message_manager.py +++ b/src/aiogram_dialog/manager/message_manager.py @@ -130,13 +130,14 @@ def _message_changed( return False - def _can_edit(self, new_message: NewMessage, old_message: OldMessage) -> bool: - # we cannot edit message if media appeared or removed - return ( - not (self.had_media(old_message) and not self.need_media(new_message)) - and not self.had_reply_keyboard(old_message) - and not self.need_reply_keyboard(new_message) - ) + def _can_edit(self, new_message: NewMessage, + old_message: OldMessage) -> bool: + # we cannot edit message if media appeared or remove + return (not (self.had_media(old_message) and + not self.need_media(new_message)) and + not self.had_reply_keyboard(old_message) and + not self.need_reply_keyboard(new_message) + ) async def show_message( self, bot: Bot, new_message: NewMessage, @@ -293,8 +294,8 @@ async def edit_message( ) -> Message: if new_message.media: if ( - old_message.media_id is not None - and new_message.media.file_id == old_message.media_id + 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) From e5c45108f5c4ff08006a6000a1871e38ebc83672 Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:52:00 +0500 Subject: [PATCH 3/4] better format --- src/aiogram_dialog/manager/message_manager.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/aiogram_dialog/manager/message_manager.py b/src/aiogram_dialog/manager/message_manager.py index c86879e4..60a7aa3f 100644 --- a/src/aiogram_dialog/manager/message_manager.py +++ b/src/aiogram_dialog/manager/message_manager.py @@ -132,12 +132,13 @@ def _message_changed( def _can_edit(self, new_message: NewMessage, old_message: OldMessage) -> bool: - # we cannot edit message if media appeared or remove - return (not (self.had_media(old_message) and - not 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 + return ( + not self.had_media(old_message) or self.need_media(new_message) + ) and not ( + self.had_reply_keyboard(old_message) or + self.need_reply_keyboard(new_message) + ) async def show_message( self, bot: Bot, new_message: NewMessage, From c36ea7ced919910848026a47779bd1015e0c2847 Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:02:34 +0500 Subject: [PATCH 4/4] BETTER CODE FORMAT --- src/aiogram_dialog/manager/message_manager.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aiogram_dialog/manager/message_manager.py b/src/aiogram_dialog/manager/message_manager.py index 60a7aa3f..0c0a766d 100644 --- a/src/aiogram_dialog/manager/message_manager.py +++ b/src/aiogram_dialog/manager/message_manager.py @@ -133,9 +133,9 @@ def _message_changed( def _can_edit(self, new_message: NewMessage, old_message: OldMessage) -> bool: # we cannot edit message if media removed - return ( - not self.had_media(old_message) or self.need_media(new_message) - ) and not ( + 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) )