Skip to content

Commit a984558

Browse files
committed
Rename methods dealing with profile pictures
1 parent 06ad65e commit a984558

7 files changed

Lines changed: 74 additions & 53 deletions

File tree

docs/source/api/methods.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ Users
111111

112112
- :meth:`~Client.get_me`
113113
- :meth:`~Client.get_users`
114-
- :meth:`~Client.get_user_photos`
115-
- :meth:`~Client.get_user_photos_count`
116-
- :meth:`~Client.set_photo`
117-
- :meth:`~Client.delete_photos`
114+
- :meth:`~Client.get_profile_photos`
115+
- :meth:`~Client.get_profile_photos_count`
116+
- :meth:`~Client.iter_profile_photos`
117+
- :meth:`~Client.set_profile_photo`
118+
- :meth:`~Client.delete_profile_photos`
118119
- :meth:`~Client.update_username`
119120
- :meth:`~Client.get_user_dc`
120121

@@ -232,10 +233,11 @@ Details
232233
.. Users
233234
.. automethod:: Client.get_me()
234235
.. automethod:: Client.get_users()
235-
.. automethod:: Client.get_user_photos()
236-
.. automethod:: Client.get_user_photos_count()
237-
.. automethod:: Client.set_photo()
238-
.. automethod:: Client.delete_photos()
236+
.. automethod:: Client.get_profile_photos()
237+
.. automethod:: Client.get_profile_photos_count()
238+
.. automethod:: Client.iter_profile_photos()
239+
.. automethod:: Client.set_profile_photo()
240+
.. automethod:: Client.delete_profile_photos()
239241
.. automethod:: Client.update_username()
240242
.. automethod:: Client.get_user_dc()
241243

pyrogram/client/ext/base_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,6 @@ def guess_mime_type(self, *args, **kwargs):
159159

160160
def guess_extension(self, *args, **kwargs):
161161
pass
162+
163+
def get_profile_photos(self, *args, **kwargs):
164+
pass

pyrogram/client/methods/users/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from .delete_photos import DeletePhotos
19+
from .delete_profile_photos import DeleteProfilePhotos
2020
from .get_me import GetMe
21+
from .get_profile_photos import GetProfilePhotos
22+
from .get_profile_photos_count import GetProfilePhotosCount
2123
from .get_user_dc import GetUserDC
22-
from .get_user_photos import GetUserPhotos
23-
from .get_user_photos_count import GetUserPhotosCount
2424
from .get_users import GetUsers
25-
from .set_photo import SetPhoto
25+
from .iter_profile_photos import IterProfilePhotos
26+
from .set_profile_photo import SetProfilePhoto
2627
from .update_username import UpdateUsername
2728

2829

2930
class Users(
30-
GetUserPhotos,
31-
SetPhoto,
32-
DeletePhotos,
31+
GetProfilePhotos,
32+
SetProfilePhoto,
33+
DeleteProfilePhotos,
3334
GetUsers,
3435
GetMe,
3536
UpdateUsername,
36-
GetUserPhotosCount,
37-
GetUserDC
37+
GetProfilePhotosCount,
38+
GetUserDC,
39+
IterProfilePhotos
3840
):
3941
pass

pyrogram/client/methods/users/delete_photos.py renamed to pyrogram/client/methods/users/delete_profile_photos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from ...ext import BaseClient
2525

2626

27-
class DeletePhotos(BaseClient):
28-
def delete_photos(
27+
class DeleteProfilePhotos(BaseClient):
28+
def delete_profile_photos(
2929
self,
3030
id: Union[str, List[str]]
3131
) -> bool:

pyrogram/client/methods/users/get_user_photos.py renamed to pyrogram/client/methods/users/get_profile_photos.py

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
from typing import Union
2020

2121
import pyrogram
22-
from pyrogram.api import functions
22+
from pyrogram.api import functions, types
2323
from ...ext import BaseClient
2424

2525

26-
class GetUserPhotos(BaseClient):
27-
def get_user_photos(
26+
class GetProfilePhotos(BaseClient):
27+
def get_profile_photos(
2828
self,
29-
user_id: Union[int, str],
29+
chat_id: Union[int, str],
3030
offset: int = 0,
3131
limit: int = 100
3232
) -> "pyrogram.Photos":
33-
"""Get a list of profile pictures for a user.
33+
"""Get a list of profile pictures for a user or a chat.
3434
3535
Parameters:
36-
user_id (``int`` | ``str``):
36+
chat_id (``int`` | ``str``):
3737
Unique identifier (int) or username (str) of the target chat.
3838
For your personal cloud (Saved Messages) you can simply use "me" or "self".
3939
For a contact that exists in your Telegram address book you can use his phone number (str).
@@ -52,14 +52,41 @@ def get_user_photos(
5252
Raises:
5353
RPCError: In case of a Telegram RPC error.
5454
"""
55-
return pyrogram.Photos._parse(
56-
self,
57-
self.send(
58-
functions.photos.GetUserPhotos(
59-
user_id=self.resolve_peer(user_id),
60-
offset=offset,
61-
max_id=0,
62-
limit=limit
55+
peer_id = self.resolve_peer(chat_id)
56+
57+
if isinstance(peer_id, types.InputPeerUser):
58+
return pyrogram.Photos._parse(
59+
self,
60+
self.send(
61+
functions.photos.GetUserPhotos(
62+
user_id=peer_id,
63+
offset=offset,
64+
max_id=0,
65+
limit=limit
66+
)
67+
)
68+
)
69+
else:
70+
new_chat_photos = pyrogram.Messages._parse(
71+
self,
72+
self.send(
73+
functions.messages.Search(
74+
peer=peer_id,
75+
q="",
76+
filter=types.InputMessagesFilterChatPhotos(),
77+
min_date=0,
78+
max_date=0,
79+
offset_id=0,
80+
add_offset=offset,
81+
limit=limit,
82+
max_id=0,
83+
min_id=0,
84+
hash=0
85+
)
6386
)
6487
)
65-
)
88+
89+
return pyrogram.Photos(
90+
total_count=new_chat_photos.total_count,
91+
photos=[m.new_chat_photo for m in new_chat_photos.messages][:limit]
92+
)

pyrogram/client/methods/users/get_user_photos_count.py renamed to pyrogram/client/methods/users/get_profile_photos_count.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@
1818

1919
from typing import Union
2020

21-
from pyrogram.api import functions, types
2221
from ...ext import BaseClient
2322

2423

25-
class GetUserPhotosCount(BaseClient):
26-
def get_user_photos_count(self, user_id: Union[int, str]) -> int:
24+
class GetProfilePhotosCount(BaseClient):
25+
def get_profile_photos_count(self, chat_id: Union[int, str]) -> int:
2726
"""Get the total count of profile pictures for a user.
2827
2928
Parameters:
30-
user_id (``int`` | ``str``):
29+
chat_id (``int`` | ``str``):
3130
Unique identifier (int) or username (str) of the target chat.
3231
For your personal cloud (Saved Messages) you can simply use "me" or "self".
3332
For a contact that exists in your Telegram address book you can use his phone number (str).
@@ -39,16 +38,4 @@ def get_user_photos_count(self, user_id: Union[int, str]) -> int:
3938
RPCError: In case of a Telegram RPC error.
4039
"""
4140

42-
r = self.send(
43-
functions.photos.GetUserPhotos(
44-
user_id=self.resolve_peer(user_id),
45-
offset=0,
46-
max_id=0,
47-
limit=1
48-
)
49-
)
50-
51-
if isinstance(r, types.photos.Photos):
52-
return len(r.photos)
53-
else:
54-
return r.count
41+
return self.get_profile_photos(chat_id, limit=1).total_count

pyrogram/client/methods/users/set_photo.py renamed to pyrogram/client/methods/users/set_profile_photo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from ...ext import BaseClient
2121

2222

23-
class SetPhoto(BaseClient):
24-
def set_photo(
23+
class SetProfilePhoto(BaseClient):
24+
def set_profile_photo(
2525
self,
2626
photo: str
2727
) -> bool:

0 commit comments

Comments
 (0)