2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Fix chat parsing

This commit is contained in:
Dan 2018-04-01 12:17:38 +02:00
parent 846fb0b637
commit 48400830e3

View File

@ -48,7 +48,7 @@ def parse_user(user: types.User):
def parse_chat(message: types.Message, users: dict, chats: dict): def parse_chat(message: types.Message, users: dict, chats: dict):
if isinstance(message.to_id, types.PeerUser): if isinstance(message.to_id, types.PeerUser):
return parse_user_chat(users[message.from_id]) return parse_user_chat(users[message.to_id.user_id if message.out else message.from_id])
elif isinstance(message.to_id, types.PeerChat): elif isinstance(message.to_id, types.PeerChat):
return parse_chat_chat(chats[message.to_id.chat_id]) return parse_chat_chat(chats[message.to_id.chat_id])
else: else:
@ -120,6 +120,11 @@ def parse_message(message: types.Message, users: dict, chats: dict):
if isinstance(size, (types.PhotoSize, types.PhotoCachedSize)): if isinstance(size, (types.PhotoSize, types.PhotoCachedSize)):
location = size.location location = size.location
if isinstance(size, types.PhotoSize):
file_size = size.size
else:
file_size = len(size.bytes)
if isinstance(location, types.FileLocation): if isinstance(location, types.FileLocation):
photo_size = pyrogram.PhotoSize( photo_size = pyrogram.PhotoSize(
file_id=encode( file_id=encode(
@ -136,7 +141,7 @@ def parse_message(message: types.Message, users: dict, chats: dict):
), ),
width=size.w, width=size.w,
height=size.h, height=size.h,
file_size=size.size file_size=file_size
) )
photo_sizes.append(photo_size) photo_sizes.append(photo_size)
@ -196,7 +201,7 @@ def parse_message_service(message: types.MessageService, users: dict, chats: dic
return pyrogram.Message( return pyrogram.Message(
message_id=message.id, message_id=message.id,
date=message.date, date=message.date,
chat=parse_chat(message.to_id, users, chats), chat=parse_chat(message, users, chats),
from_user=parse_user(users.get(message.from_id, None)), from_user=parse_user(users.get(message.from_id, None)),
new_chat_members=new_chat_members, new_chat_members=new_chat_members,
left_chat_member=left_chat_member, left_chat_member=left_chat_member,