Fix edge-case when pinned action is MessageActionHistoryClear (#49)

* fix: edge-case when pinned action is `MessageActionHistoryClear`

* fix: parsing of `ChannelAdminLogEventActionUpdatePinned` action
This commit is contained in:
Danipulok 2024-04-30 10:25:57 +03:00 committed by GitHub
parent 2b53d394d2
commit fc89b93b5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -123,6 +123,10 @@ class ChatEventAction(AutoName):
MESSAGE_UNPINNED = auto() MESSAGE_UNPINNED = auto()
"a message has been unpinned (see ``unpinned_message``)" "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() CREATED_FORUM_TOPIC = auto()
"a new forum topic has been created (see `created_forum_topic`)" "a new forum topic has been created (see `created_forum_topic`)"

View File

@ -433,12 +433,14 @@ class ChatEvent(Object):
elif isinstance(action, raw.types.ChannelAdminLogEventActionUpdatePinned): elif isinstance(action, raw.types.ChannelAdminLogEventActionUpdatePinned):
message = action.message 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) pinned_message = await types.Message._parse(client, message, users, chats)
action = enums.ChatEventAction.MESSAGE_PINNED 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) unpinned_message = await types.Message._parse(client, message, users, chats)
action = enums.ChatEventAction.MESSAGE_UNPINNED action = enums.ChatEventAction.MESSAGE_UNPINNED
else:
action = enums.ChatEventAction.MESSAGE_PIN_CHANGED
elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteEdit): elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteEdit):
old_invite_link = types.ChatInviteLink._parse(client, action.prev_invite, users) old_invite_link = types.ChatInviteLink._parse(client, action.prev_invite, users)