diff --git a/pyrogram/client/methods/users/get_profile_photos.py b/pyrogram/client/methods/users/get_profile_photos.py index e2845c8d..3ffeae39 100644 --- a/pyrogram/client/methods/users/get_profile_photos.py +++ b/pyrogram/client/methods/users/get_profile_photos.py @@ -21,6 +21,7 @@ from typing import Union, List import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import utils + from ...ext import BaseClient @@ -55,18 +56,7 @@ class GetProfilePhotos(BaseClient): """ peer_id = self.resolve_peer(chat_id) - if isinstance(peer_id, (types.InputPeerUser, types.InputPeerSelf)): - r = self.send( - functions.photos.GetUserPhotos( - user_id=peer_id, - offset=offset, - max_id=0, - limit=limit - ) - ) - - return pyrogram.List(pyrogram.Photo._parse(self, photo) for photo in r.photos) - else: + if isinstance(peer_id, types.InputPeerChannel): r = utils.parse_messages( self, self.send( @@ -87,3 +77,14 @@ class GetProfilePhotos(BaseClient): ) return pyrogram.List([message.new_chat_photo for message in r][:limit]) + else: + r = self.send( + functions.photos.GetUserPhotos( + user_id=peer_id, + offset=offset, + max_id=0, + limit=limit + ) + ) + + return pyrogram.List(pyrogram.Photo._parse(self, photo) for photo in r.photos) diff --git a/pyrogram/client/methods/users/get_profile_photos_count.py b/pyrogram/client/methods/users/get_profile_photos_count.py index a65e0ada..bf00a10b 100644 --- a/pyrogram/client/methods/users/get_profile_photos_count.py +++ b/pyrogram/client/methods/users/get_profile_photos_count.py @@ -18,6 +18,8 @@ from typing import Union +from pyrogram.api import functions, types + from ...ext import BaseClient @@ -38,4 +40,28 @@ class GetProfilePhotosCount(BaseClient): RPCError: In case of a Telegram RPC error. """ - return self.get_profile_photos(chat_id, limit=1).total_count + peer_id = self.resolve_peer(chat_id) + + if isinstance(peer_id, types.InputPeerChannel): + r = self.send( + functions.messages.GetSearchCounters( + peer=peer_id, + filters=[types.InputMessagesFilterChatPhotos()], + ) + ) + + return r[0].count + else: + r = self.send( + functions.photos.GetUserPhotos( + user_id=peer_id, + offset=0, + max_id=0, + limit=1 + ) + ) + + if isinstance(r, types.photos.Photos): + return len(r.photos) + else: + return r.count