diff --git a/pyrogram/client/types/user_and_chats/chat_photo.py b/pyrogram/client/types/user_and_chats/chat_photo.py index e5877309..485777e5 100644 --- a/pyrogram/client/types/user_and_chats/chat_photo.py +++ b/pyrogram/client/types/user_and_chats/chat_photo.py @@ -16,7 +16,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from struct import pack + +from pyrogram.api import types from pyrogram.api.core import Object +from ...ext.utils import encode class ChatPhoto(Object): @@ -32,6 +36,42 @@ class ChatPhoto(Object): ID = 0xb0700015 - def __init__(self, small_file_id: str, big_file_id: str): - self.small_file_id = small_file_id # string - self.big_file_id = big_file_id # string + def __init__(self, small_file_id: str, big_file_id: str, *, + client=None, raw=None): + self.small_file_id = small_file_id + self.big_file_id = big_file_id + + self._client = client + self.raw = raw + + @staticmethod + def parse(client, chat_photo: types.UserProfilePhoto or types.ChatPhoto): + if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)): + return None + + if not isinstance(chat_photo.photo_small, types.FileLocation): + return None + + if not isinstance(chat_photo.photo_big, types.FileLocation): + return None + + photo_id = getattr(chat_photo, "photo_id", 0) + loc_small = chat_photo.photo_small + loc_big = chat_photo.photo_big + + return ChatPhoto( + small_file_id=encode( + pack( + "