Skip to content

Commit a73f990

Browse files
committed
Improve parsing of Chat
1 parent 8a08dcb commit a73f990

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • pyrogram/types/user_and_chats

pyrogram/types/user_and_chats/chat.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,17 @@ def _parse(
245245
chats: dict,
246246
is_chat: bool
247247
) -> "Chat":
248+
from_id = utils.get_raw_peer_id(message.from_id)
249+
peer_id = utils.get_raw_peer_id(message.peer_id)
250+
chat_id = (peer_id or from_id) if is_chat else (from_id or peer_id)
251+
248252
if isinstance(message.peer_id, raw.types.PeerUser):
249-
user_id = message.peer_id.user_id if is_chat else message.from_id.user_id
250-
return Chat._parse_user_chat(client, users[user_id])
253+
return Chat._parse_user_chat(client, users[chat_id])
251254

252255
if isinstance(message.peer_id, raw.types.PeerChat):
253-
chat_id = message.peer_id.chat_id if is_chat else message.from_id.chat_id
254256
return Chat._parse_chat_chat(client, chats[chat_id])
255257

256-
channel_id = message.peer_id.channel_id if is_chat else message.from_id.channel_id
257-
return Chat._parse_channel_chat(client, chats[channel_id])
258+
return Chat._parse_channel_chat(client, chats[chat_id])
258259

259260
@staticmethod
260261
def _parse_dialog(client, peer, users: dict, chats: dict):

0 commit comments

Comments
 (0)