Skip to content

Commit ebf2d68

Browse files
committed
Add new method unpin_all_chat_messages
1 parent c7e4e55 commit ebf2d68

4 files changed

Lines changed: 60 additions & 3 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def get_title_list(s: str) -> list:
197197
set_chat_permissions
198198
pin_chat_message
199199
unpin_chat_message
200+
unpin_all_chat_messages
200201
get_chat
201202
get_chat_member
202203
get_chat_members

pyrogram/methods/chats/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .set_slow_mode import SetSlowMode
5050
from .unarchive_chats import UnarchiveChats
5151
from .unban_chat_member import UnbanChatMember
52+
from .unpin_all_chat_messages import UnpinAllChatMessages
5253
from .unpin_chat_message import UnpinChatMessage
5354
from .update_chat_username import UpdateChatUsername
5455

@@ -88,6 +89,7 @@ class Chats(
8889
GetNearbyChats,
8990
SetAdministratorTitle,
9091
SetSlowMode,
91-
DeleteUserHistory
92+
DeleteUserHistory,
93+
UnpinAllChatMessages
9294
):
9395
pass
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Union
20+
21+
from pyrogram import raw
22+
from pyrogram.scaffold import Scaffold
23+
24+
25+
class UnpinAllChatMessages(Scaffold):
26+
async def unpin_all_chat_messages(
27+
self,
28+
chat_id: Union[int, str],
29+
) -> bool:
30+
"""Use this method to clear the list of pinned messages in a chat.
31+
If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have
32+
the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel.
33+
34+
Parameters:
35+
chat_id (``int`` | ``str``):
36+
Unique identifier (int) or username (str) of the target chat.
37+
38+
Returns:
39+
``bool``: True on success.
40+
41+
Example:
42+
.. code-block:: python
43+
44+
# Unpin all chat messages
45+
app.unpin_all_chat_messages(chat_id)
46+
"""
47+
await self.send(
48+
raw.functions.messages.UnpinAllMessages(
49+
peer=await self.resolve_peer(chat_id)
50+
)
51+
)
52+
53+
return True

pyrogram/methods/chats/unpin_chat_message.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UnpinChatMessage(Scaffold):
2626
async def unpin_chat_message(
2727
self,
2828
chat_id: Union[int, str],
29-
message_id: int
29+
message_id: int = 0
3030
) -> bool:
3131
"""Unpin a message in a group, channel or your own chat.
3232
You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin
@@ -36,8 +36,9 @@ async def unpin_chat_message(
3636
chat_id (``int`` | ``str``):
3737
Unique identifier (int) or username (str) of the target chat.
3838
39-
message_id (``int``):
39+
message_id (``int``, *optional*):
4040
Identifier of a message to unpin.
41+
If not specified, the most recent pinned message (by sending date) will be unpinned.
4142
4243
Returns:
4344
``bool``: True on success.

0 commit comments

Comments
 (0)