Refactor UserProfilePhotos

This commit is contained in:
Dan 2018-12-17 13:51:08 +01:00
parent a683e3e917
commit 8cbb9c9316
2 changed files with 15 additions and 2 deletions

View File

@ -16,8 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import pyrogram
from pyrogram.api import functions
from ...ext import BaseClient, utils
from ...ext import BaseClient
class GetUserProfilePhotos(BaseClient):
@ -47,7 +48,8 @@ class GetUserProfilePhotos(BaseClient):
Raises:
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
return utils.parse_profile_photos(
return pyrogram.UserProfilePhotos.parse(
self,
self.send(
functions.photos.GetUserPhotos(
user_id=self.resolve_peer(user_id),

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.api import types
from .photo import Photo
from ..pyrogram_type import PyrogramType
@ -35,3 +37,12 @@ class UserProfilePhotos(PyrogramType):
self.total_count = total_count
self.photos = photos
@staticmethod
def parse(client, photos) -> "UserProfilePhotos":
return UserProfilePhotos(
total_count=len(photos.photos) if isinstance(photos, types.photos.Photos) else photos.count,
photos=[Photo.parse(client, photo) for photo in photos.photos],
client=client,
raw=photos
)