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:
parent
a21858a262
commit
4f2928e7b5
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user