Fix wrong sender_chat

This commit is contained in:
Dan 2021-12-07 22:39:56 +01:00
parent e2cce1b1e6
commit 439935b401
2 changed files with 17 additions and 8 deletions

View File

@ -513,12 +513,12 @@ class Message(Object, Update):
service_type = "voice_chat_members_invited" service_type = "voice_chat_members_invited"
from_user = types.User._parse(client, users.get(user_id, 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( parsed_message = Message(
message_id=message.id, message_id=message.id,
date=message.date, 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, from_user=from_user,
sender_chat=sender_chat, sender_chat=sender_chat,
service=service_type, service=service_type,
@ -707,12 +707,12 @@ class Message(Object, Update):
reply_markup = None reply_markup = None
from_user = types.User._parse(client, users.get(user_id, 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( parsed_message = Message(
message_id=message.id, message_id=message.id,
date=message.date, 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, from_user=from_user,
sender_chat=sender_chat, sender_chat=sender_chat,
text=( text=(

View File

@ -238,14 +238,23 @@ class Chat(Object):
) )
@staticmethod @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): 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): 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 @staticmethod
def _parse_dialog(client, peer, users: dict, chats: dict): def _parse_dialog(client, peer, users: dict, chats: dict):