From 832f1f6d53c3196f3994e8376a8a9a19d74ec188 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:47:32 +0100 Subject: [PATCH] Update pin/unpin_chat_message and Message.pin/unpin --- pyrogram/methods/chats/pin_chat_message.py | 12 +++++-- pyrogram/methods/chats/unpin_chat_message.py | 11 ++++-- pyrogram/types/messages_and_media/message.py | 37 ++++++++++++++++++-- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py index a357aab9..39ddd75e 100644 --- a/pyrogram/methods/chats/pin_chat_message.py +++ b/pyrogram/methods/chats/pin_chat_message.py @@ -27,7 +27,8 @@ class PinChatMessage(Scaffold): self, chat_id: Union[int, str], message_id: int, - disable_notification: bool = None + disable_notification: bool = False, + both_sides: bool = False, ) -> bool: """Pin 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 right in @@ -40,10 +41,14 @@ class PinChatMessage(Scaffold): message_id (``int``): Identifier of a message to pin. - disable_notification (``bool``): + disable_notification (``bool``, *optional*): Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels. + both_sides (``bool``, *optional*): + Pass True to pin the message for both sides (you and recipient). + Applicable to private chats only. Defaults to False. + Returns: ``bool``: True on success. @@ -60,7 +65,8 @@ class PinChatMessage(Scaffold): raw.functions.messages.UpdatePinnedMessage( peer=await self.resolve_peer(chat_id), id=message_id, - silent=disable_notification or None + silent=disable_notification or None, + pm_oneside=not both_sides or None ) ) diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py index 3ee7814d..52e533ed 100644 --- a/pyrogram/methods/chats/unpin_chat_message.py +++ b/pyrogram/methods/chats/unpin_chat_message.py @@ -25,7 +25,8 @@ from pyrogram.scaffold import Scaffold class UnpinChatMessage(Scaffold): async def unpin_chat_message( self, - chat_id: Union[int, str] + chat_id: Union[int, str], + message_id: int ) -> 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 @@ -35,18 +36,22 @@ class UnpinChatMessage(Scaffold): chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. + message_id (``int``): + Identifier of a message to unpin. + Returns: ``bool``: True on success. Example: .. code-block:: python - app.unpin_chat_message(chat_id) + app.unpin_chat_message(chat_id, message_id) """ await self.send( raw.functions.messages.UpdatePinnedMessage( peer=await self.resolve_peer(chat_id), - id=0 + id=message_id, + unpin=True ) ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index df6a5a95..c964fc3d 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3117,7 +3117,7 @@ class Message(Object, Update): options=option ) - async def pin(self, disable_notification: bool = None) -> bool: + async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> bool: """Bound method *pin* of :obj:`~pyrogram.types.Message`. Use as a shortcut for: @@ -3139,6 +3139,10 @@ class Message(Object, Update): Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels. + both_sides (``bool``, *optional*): + Pass True to pin the message for both sides (you and recipient). + Applicable to private chats only. Defaults to False. + Returns: True on success. @@ -3148,5 +3152,34 @@ class Message(Object, Update): return await self._client.pin_chat_message( chat_id=self.chat.id, message_id=self.message_id, - disable_notification=disable_notification + disable_notification=disable_notification, + both_sides=both_sides + ) + + async def unpin(self) -> bool: + """Bound method *unpin* of :obj:`~pyrogram.types.Message`. + + Use as a shortcut for: + + .. code-block:: python + + client.unpin_chat_message( + chat_id=message.chat.id, + message_id=message_id + ) + + Example: + .. code-block:: python + + message.unpin() + + Returns: + True on success. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + return await self._client.pin_chat_message( + chat_id=self.chat.id, + message_id=self.message_id )