Skip to content

Commit 87d8d8b

Browse files
committed
Rename methods and add proper docs
1 parent 29b12e1 commit 87d8d8b

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def get_title_list(s: str) -> list:
226226
get_chat_online_count
227227
get_send_as_chats
228228
set_send_as_chat
229+
set_chat_protected_content
229230
""",
230231
users="""
231232
Users
@@ -515,7 +516,7 @@ def get_title_list(s: str) -> list:
515516
Chat.join
516517
Chat.leave
517518
Chat.mark_unread
518-
Chat.no_forwards
519+
Chat.set_protected_content
519520
""",
520521
user="""
521522
User

pyrogram/methods/chats/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .set_chat_description import SetChatDescription
4949
from .set_chat_permissions import SetChatPermissions
5050
from .set_chat_photo import SetChatPhoto
51+
from .set_chat_protected_content import SetChatProtectedContent
5152
from .set_chat_title import SetChatTitle
5253
from .set_send_as_chat import SetSendAsChat
5354
from .set_slow_mode import SetSlowMode
@@ -56,7 +57,6 @@
5657
from .unpin_all_chat_messages import UnpinAllChatMessages
5758
from .unpin_chat_message import UnpinChatMessage
5859
from .update_chat_username import UpdateChatUsername
59-
from .toggle_no_forwards import ToggleNoForwards
6060

6161

6262
class Chats(
@@ -100,6 +100,6 @@ class Chats(
100100
GetChatOnlineCount,
101101
GetSendAsChats,
102102
SetSendAsChat,
103-
ToggleNoForwards
103+
SetChatProtectedContent
104104
):
105105
pass

pyrogram/methods/chats/toggle_no_forwards.py renamed to pyrogram/methods/chats/set_chat_protected_content.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,30 @@
2222
from pyrogram.scaffold import Scaffold
2323

2424

25-
class ToggleNoForwards(Scaffold):
26-
async def toggle_no_forwards(
25+
class SetChatProtectedContent(Scaffold):
26+
async def set_chat_protected_content(
2727
self,
2828
chat_id: Union[int, str],
29-
enabled: bool = False
29+
enabled: bool
3030
) -> bool:
31-
"""Toggle no forwards chat option
31+
"""Set the chat protected content setting.
3232
3333
Parameters:
3434
chat_id (``int`` | ``str``):
3535
Unique identifier (int) or username (str) of the target chat.
3636
37-
enabled (``bool``, *optional*):
38-
Pass True to enable no forwards
37+
enabled (``bool``):
38+
Pass True to enable the protected content setting, False to disable.
3939
4040
Returns:
4141
``bool``: On success, True is returned.
4242
"""
4343

44-
return await self.send(
44+
await self.send(
4545
functions.messages.ToggleNoForwards(
4646
peer=await self.resolve_peer(chat_id),
4747
enabled=enabled
4848
)
4949
)
50+
51+
return True

pyrogram/types/user_and_chats/chat.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
325325
send_as_raw = users[default_send_as.user_id]
326326
else:
327327
send_as_raw = chats[default_send_as.channel_id]
328-
328+
329329
parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw)
330330

331331
if full_chat.pinned_msg_id:
@@ -1012,25 +1012,29 @@ async def mark_unread(self, ) -> bool:
10121012

10131013
return await self._client.mark_chat_unread(self.id)
10141014

1015-
async def no_forwards(self, enabled: bool = False) -> bool:
1016-
"""Bound method *toggle_no_forwards* of :obj:`~pyrogram.types.Chat`.
1015+
async def set_protected_content(self, enabled: bool) -> bool:
1016+
"""Bound method *set_protected_content* of :obj:`~pyrogram.types.Chat`.
10171017
10181018
Use as a shortcut for:
10191019
10201020
.. code-block:: python
10211021
1022-
client.toggle_no_forwards(chat_id, enabled)
1022+
client.set_chat_protected_content(chat_id, enabled)
1023+
1024+
Parameters:
1025+
enabled (``bool``):
1026+
Pass True to enable the protected content setting, False to disable.
10231027
10241028
Example:
10251029
.. code-block:: python
10261030
1027-
chat.toggle_no_forwards(True)
1031+
chat.set_protected_content(enabled)
10281032
10291033
Returns:
10301034
``bool``: On success, True is returned.
10311035
"""
10321036

1033-
return await self._client.toggle_no_forwards(
1037+
return await self._client.set_chat_protected_content(
10341038
self.id,
10351039
enabled=enabled
10361040
)

0 commit comments

Comments
 (0)