Skip to content

Commit 1a7d9a2

Browse files
committed
Try to return the service message (when applicable) in the set_chat_photo
- Documentation Fixes
1 parent 5111b74 commit 1a7d9a2

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

compiler/errors/source/406_NOT_ACCEPTABLE.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ TOPIC_CLOSED This topic was closed, you can't send messages to it anymore.
2323
TOPIC_DELETED The specified topic was deleted.
2424
USERPIC_PRIVACY_REQUIRED You need to disable privacy settings for your profile picture in order to make your geolocation public.
2525
USERPIC_UPLOAD_REQUIRED You must have a profile picture to publish your geolocation.
26-
USER_RESTRICTED You're spamreported, you can't create channels or chats.
26+
USER_RESTRICTED You're spamreported, you can't create channels or chats.

docs/source/releases/changes-in-this-fork.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ If you found any issue or have any suggestions, feel free to make `an issue <htt
1414
| Scheme layer used: 186 |
1515
+------------------------+
1616

17+
- Try to return the service message (when applicable) in the methods :meth:`~pyrogram.Client.set_chat_photo`, :meth:`~pyrogram.types.Chat.set_photo`.
18+
- Added the methods :meth:`~pyrogram.Client.get_payment_form` and :meth:`~pyrogram.Client.send_payment_form` `#89 <https://github.com/TelegramPlayGround/pyrogram/pull/89>`__.
1719
- Added the fields ``expired_member_count``, ``subscription_period`` and ``subscription_price`` to the class :obj:`~pyrogram.types.ChatInviteLink`.
1820
- Added the field ``can_enable_paid_reaction`` to the class :obj:`~pyrogram.types.Chat`.
1921
- Added ``link`` property to :obj:`~pyrogram.types.Story` and fixed the ``link`` property in :obj:`~pyrogram.types.Message`.

pyrogram/methods/chats/set_chat_photo.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
from typing import Union, BinaryIO
2121

2222
import pyrogram
23-
from pyrogram import raw
24-
from pyrogram import utils
23+
from pyrogram import raw, types, utils
2524
from pyrogram.file_id import FileType
2625

2726

@@ -33,7 +32,7 @@ async def set_chat_photo(
3332
photo: Union[str, BinaryIO] = None,
3433
video: Union[str, BinaryIO] = None,
3534
video_start_ts: float = None,
36-
) -> bool:
35+
) -> Union["types.Message", bool]:
3736
"""Set a new chat photo or video (H.264/MPEG-4 AVC video, max 5 seconds).
3837
3938
The ``photo`` and ``video`` arguments are mutually exclusive.
@@ -61,7 +60,8 @@ async def set_chat_photo(
6160
The timestamp in seconds of the video frame to use as photo profile preview.
6261
6362
Returns:
64-
``bool``: True on success.
63+
:obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
64+
otherwise, in case a message object couldn't be returned, True is returned.
6565
6666
Raises:
6767
ValueError: if a chat_id belongs to user.
@@ -102,14 +102,14 @@ async def set_chat_photo(
102102
)
103103

104104
if isinstance(peer, raw.types.InputPeerChat):
105-
await self.invoke(
105+
r = await self.invoke(
106106
raw.functions.messages.EditChatPhoto(
107107
chat_id=peer.chat_id,
108108
photo=photo,
109109
)
110110
)
111111
elif isinstance(peer, raw.types.InputPeerChannel):
112-
await self.invoke(
112+
r = await self.invoke(
113113
raw.functions.channels.EditPhoto(
114114
channel=peer,
115115
photo=photo
@@ -118,4 +118,14 @@ async def set_chat_photo(
118118
else:
119119
raise ValueError(f'The chat_id "{chat_id}" belongs to a user')
120120

121-
return True
121+
for i in r.updates:
122+
if isinstance(i, (raw.types.UpdateNewMessage, raw.types.UpdateNewChannelMessage)):
123+
return await types.Message._parse(
124+
self,
125+
i.message,
126+
{i.id: i for i in r.users},
127+
{i.id: i for i in r.chats},
128+
replies=self.fetch_replies
129+
)
130+
else:
131+
return True

pyrogram/types/user_and_chats/chat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ async def set_photo(
859859
photo: Union[str, BinaryIO] = None,
860860
video: Union[str, BinaryIO] = None,
861861
video_start_ts: float = None,
862-
) -> bool:
862+
) -> Union["types.Message", bool]:
863863
"""Bound method *set_photo* of :obj:`~pyrogram.types.Chat`.
864864
865865
Use as a shortcut for:
@@ -902,7 +902,8 @@ async def set_photo(
902902
The timestamp in seconds of the video frame to use as photo profile preview.
903903
904904
Returns:
905-
``bool``: True on success.
905+
:obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
906+
otherwise, in case a message object couldn't be returned, True is returned.
906907
907908
Raises:
908909
RPCError: In case of a Telegram RPC error.

0 commit comments

Comments
 (0)