diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index fdb4972d..479ee2b8 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -197,6 +197,7 @@ def pyrogram_api(): set_chat_permissions pin_chat_message unpin_chat_message + unpin_all_chat_messages get_chat get_chat_member get_chat_members diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index b55d1be7..8bd785c3 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -49,6 +49,7 @@ from .set_chat_title import SetChatTitle from .set_slow_mode import SetSlowMode from .unarchive_chats import UnarchiveChats from .unban_chat_member import UnbanChatMember +from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername @@ -88,6 +89,7 @@ class Chats( GetNearbyChats, SetAdministratorTitle, SetSlowMode, - DeleteUserHistory + DeleteUserHistory, + UnpinAllChatMessages ): pass diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py new file mode 100644 index 00000000..a6f325a4 --- /dev/null +++ b/pyrogram/methods/chats/unpin_all_chat_messages.py @@ -0,0 +1,53 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2020 Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +from pyrogram import raw +from pyrogram.scaffold import Scaffold + + +class UnpinAllChatMessages(Scaffold): + async def unpin_all_chat_messages( + self, + chat_id: Union[int, str], + ) -> bool: + """Use this method to clear the list of pinned messages in a chat. + If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have + the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + ``bool``: True on success. + + Example: + .. code-block:: python + + # Unpin all chat messages + app.unpin_all_chat_messages(chat_id) + """ + await self.send( + raw.functions.messages.UnpinAllMessages( + peer=await self.resolve_peer(chat_id) + ) + ) + + return True diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py index 52e533ed..79a4a4c2 100644 --- a/pyrogram/methods/chats/unpin_chat_message.py +++ b/pyrogram/methods/chats/unpin_chat_message.py @@ -26,7 +26,7 @@ class UnpinChatMessage(Scaffold): async def unpin_chat_message( self, chat_id: Union[int, str], - message_id: int + message_id: int = 0 ) -> bool: """Unpin a message in a group, channel or your own chat. You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin @@ -36,8 +36,9 @@ class UnpinChatMessage(Scaffold): chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - message_id (``int``): + message_id (``int``, *optional*): Identifier of a message to unpin. + If not specified, the most recent pinned message (by sending date) will be unpinned. Returns: ``bool``: True on success.