From a73f990667ce2b2b396f7af2a46203a418da47da Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 8 Dec 2021 07:46:41 +0100 Subject: [PATCH] Improve parsing of Chat --- pyrogram/types/user_and_chats/chat.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 40bf2023..cf607c66 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -245,16 +245,17 @@ class Chat(Object): chats: dict, is_chat: bool ) -> "Chat": + from_id = utils.get_raw_peer_id(message.from_id) + peer_id = utils.get_raw_peer_id(message.peer_id) + chat_id = (peer_id or from_id) if is_chat else (from_id or peer_id) + if isinstance(message.peer_id, raw.types.PeerUser): - 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]) + return Chat._parse_user_chat(client, users[chat_id]) if isinstance(message.peer_id, raw.types.PeerChat): - 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]) - 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]) + return Chat._parse_channel_chat(client, chats[chat_id]) @staticmethod def _parse_dialog(client, peer, users: dict, chats: dict):