From 7f3aa43ad4d4bff888e1136e9ed98b17a77cab3d Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 27 Apr 2020 21:16:45 +0200 Subject: [PATCH] Rely on types.UpdateChatPinnedMessage for chat unpins Fixes #1405, probably. --- telethon/events/chataction.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/telethon/events/chataction.py b/telethon/events/chataction.py index dd80b535..34d9c693 100644 --- a/telethon/events/chataction.py +++ b/telethon/events/chataction.py @@ -38,6 +38,10 @@ class ChatAction(EventBuilder): return cls.Event(types.PeerChannel(update.channel_id), unpin=True) + elif isinstance(update, types.UpdateChatPinnedMessage) and update.id == 0: + return cls.Event(types.PeerChat(update.chat_id), + unpin=True) + elif isinstance(update, types.UpdateChatParticipantAdd): return cls.Event(types.PeerChat(update.chat_id), added_by=update.inviter_id or True, @@ -104,8 +108,9 @@ class ChatAction(EventBuilder): return cls.Event(msg, users=msg.from_id, new_photo=True) - elif isinstance(action, types.MessageActionPinMessage): - # Telegram always sends this service message for new pins + elif isinstance(action, types.MessageActionPinMessage) and msg.reply_to_msg_id: + # Seems to not be reliable on unpins, but when pinning + # we prefer this because we know who caused it. return cls.Event(msg, users=msg.from_id, new_pin=msg.reply_to_msg_id)