From fc89b93b5a70be0204a10b21bfeaf0333b63f592 Mon Sep 17 00:00:00 2001 From: Danipulok <45077699+Danipulok@users.noreply.github.com> Date: Tue, 30 Apr 2024 10:25:57 +0300 Subject: [PATCH] Fix edge-case when pinned action is `MessageActionHistoryClear` (#49) * fix: edge-case when pinned action is `MessageActionHistoryClear` * fix: parsing of `ChannelAdminLogEventActionUpdatePinned` action --- pyrogram/enums/chat_event_action.py | 4 ++++ pyrogram/types/user_and_chats/chat_event.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrogram/enums/chat_event_action.py b/pyrogram/enums/chat_event_action.py index eff86f37..921cb90d 100644 --- a/pyrogram/enums/chat_event_action.py +++ b/pyrogram/enums/chat_event_action.py @@ -123,6 +123,10 @@ class ChatEventAction(AutoName): MESSAGE_UNPINNED = auto() "a message has been unpinned (see ``unpinned_message``)" + MESSAGE_PIN_CHANGED = auto() + "a message has been pinned or unpinned but actual message is not received" + "should never be used in end-user code, only for correct parsing" + CREATED_FORUM_TOPIC = auto() "a new forum topic has been created (see `created_forum_topic`)" diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py index 9faea6a0..ef76e139 100644 --- a/pyrogram/types/user_and_chats/chat_event.py +++ b/pyrogram/types/user_and_chats/chat_event.py @@ -433,12 +433,14 @@ class ChatEvent(Object): elif isinstance(action, raw.types.ChannelAdminLogEventActionUpdatePinned): message = action.message - if message.pinned: + if isinstance(message, raw.types.Message) and message.pinned: pinned_message = await types.Message._parse(client, message, users, chats) action = enums.ChatEventAction.MESSAGE_PINNED - else: + elif isinstance(message, raw.types.Message) and not message.pinned: unpinned_message = await types.Message._parse(client, message, users, chats) action = enums.ChatEventAction.MESSAGE_UNPINNED + else: + action = enums.ChatEventAction.MESSAGE_PIN_CHANGED elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteEdit): old_invite_link = types.ChatInviteLink._parse(client, action.prev_invite, users)