Update pin/unpin_chat_message and Message.pin/unpin

This commit is contained in:
Dan 2020-10-31 16:47:32 +01:00
parent 431abd6a51
commit 832f1f6d53
3 changed files with 52 additions and 8 deletions

View File

@ -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
)
)

View File

@ -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
)
)

View File

@ -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
)