From 439935b4012eb03ad632c46191055227e9e7c566 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 7 Dec 2021 22:39:56 +0100 Subject: [PATCH] Fix wrong sender_chat --- pyrogram/types/messages_and_media/message.py | 8 ++++---- pyrogram/types/user_and_chats/chat.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index aaab0af0..85db6842 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -513,12 +513,12 @@ class Message(Object, Update): service_type = "voice_chat_members_invited" from_user = types.User._parse(client, users.get(user_id, None)) - sender_chat = types.Chat._parse(client, message, users, chats) if not from_user else None + sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None parsed_message = Message( message_id=message.id, date=message.date, - chat=types.Chat._parse(client, message, users, chats), + chat=types.Chat._parse(client, message, users, chats, is_chat=True), from_user=from_user, sender_chat=sender_chat, service=service_type, @@ -707,12 +707,12 @@ class Message(Object, Update): reply_markup = None from_user = types.User._parse(client, users.get(user_id, None)) - sender_chat = types.Chat._parse(client, message, users, chats) if not from_user else None + sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None parsed_message = Message( message_id=message.id, date=message.date, - chat=types.Chat._parse(client, message, users, chats), + chat=types.Chat._parse(client, message, users, chats, is_chat=True), from_user=from_user, sender_chat=sender_chat, text=( diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 8930bf3a..59db7a62 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -238,14 +238,23 @@ class Chat(Object): ) @staticmethod - def _parse(client, message: Union[raw.types.Message, raw.types.MessageService], users: dict, chats: dict) -> "Chat": + def _parse( + client, + message: Union[raw.types.Message, raw.types.MessageService], + users: dict, + chats: dict, + is_chat: bool + ) -> "Chat": if isinstance(message.peer_id, raw.types.PeerUser): - return Chat._parse_user_chat(client, users[message.peer_id.user_id]) + user_id = message.peer_id.user_id if is_chat else message.from_id.user_id + return Chat._parse_user_chat(client, users[user_id]) if isinstance(message.peer_id, raw.types.PeerChat): - return Chat._parse_chat_chat(client, chats[message.peer_id.chat_id]) + chat_id = message.peer_id.chat_id if is_chat else message.from_id.chat_id + return Chat._parse_chat_chat(client, chats[chat_id]) - return Chat._parse_channel_chat(client, chats[message.peer_id.channel_id]) + channel_id = message.peer_id.channel_id if is_chat else message.from_id.channel_id + return Chat._parse_channel_chat(client, chats[channel_id]) @staticmethod def _parse_dialog(client, peer, users: dict, chats: dict):