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

Improve get_profile_photos and get_profile_photos_count

This commit is contained in:
Dan 2019-06-12 11:37:43 +02:00
parent a21858a262
commit 4f2928e7b5
2 changed files with 40 additions and 13 deletions

View File

@ -21,6 +21,7 @@ from typing import Union, List
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import utils from pyrogram.client.ext import utils
from ...ext import BaseClient from ...ext import BaseClient
@ -55,18 +56,7 @@ class GetProfilePhotos(BaseClient):
""" """
peer_id = self.resolve_peer(chat_id) peer_id = self.resolve_peer(chat_id)
if isinstance(peer_id, (types.InputPeerUser, types.InputPeerSelf)): if isinstance(peer_id, types.InputPeerChannel):
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:
r = utils.parse_messages( r = utils.parse_messages(
self, self,
self.send( self.send(
@ -87,3 +77,14 @@ class GetProfilePhotos(BaseClient):
) )
return pyrogram.List([message.new_chat_photo for message in r][:limit]) 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)

View File

@ -18,6 +18,8 @@
from typing import Union from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
@ -38,4 +40,28 @@ class GetProfilePhotosCount(BaseClient):
RPCError: In case of a Telegram RPC error. 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