From 85ee6c378560e5c9d035c5e68a81f1e7db485051 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 7 Dec 2021 19:40:06 +0100 Subject: [PATCH] Fetch user details in case they are missing --- pyrogram/types/messages_and_media/message.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 403411fc..6f2539b8 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -433,6 +433,16 @@ class Message(Object, Update): is_scheduled: bool = False, replies: int = 1 ): + user_id = utils.get_raw_peer_id(message.from_id) or utils.get_raw_peer_id(message.peer_id) + if user_id not in users: + r = (await client.send( + raw.functions.users.GetUsers( + id=[await client.resolve_peer(user_id)] + ) + ))[0] + + users[r.id] = r + if isinstance(message, raw.types.MessageEmpty): return Message(message_id=message.id, empty=True, client=client) @@ -499,8 +509,7 @@ class Message(Object, Update): voice_chat_members_invited = types.VoiceChatMembersInvited._parse(client, action, users) service_type = "voice_chat_members_invited" - user = utils.get_raw_peer_id(message.from_id) or utils.get_raw_peer_id(message.peer_id) - from_user = types.User._parse(client, users.get(user, 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 parsed_message = Message( @@ -554,8 +563,6 @@ class Message(Object, Update): except MessageIdsEmpty: pass - - return parsed_message if isinstance(message, raw.types.Message): @@ -696,8 +703,7 @@ class Message(Object, Update): else: reply_markup = None - user = utils.get_raw_peer_id(message.from_id) or utils.get_raw_peer_id(message.peer_id) - from_user = types.User._parse(client, users.get(user, 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 parsed_message = Message(