mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-16 18:16:39 +00:00
Add method to unpin messages
This commit is contained in:
parent
9e3cb8180b
commit
935ee2242d
@ -1260,7 +1260,7 @@ class MessageMethods:
|
|||||||
|
|
||||||
message (`int` | `Message <telethon.tl.custom.message.Message>`):
|
message (`int` | `Message <telethon.tl.custom.message.Message>`):
|
||||||
The message or the message ID to pin. If it's
|
The message or the message ID to pin. If it's
|
||||||
`None`, the message will be unpinned instead.
|
`None`, all messages will be unpinned instead.
|
||||||
|
|
||||||
notify (`bool`, optional):
|
notify (`bool`, optional):
|
||||||
Whether the pin should notify people or not.
|
Whether the pin should notify people or not.
|
||||||
@ -1272,18 +1272,55 @@ class MessageMethods:
|
|||||||
message = await client.send_message(chat, 'Pinotifying is fun!')
|
message = await client.send_message(chat, 'Pinotifying is fun!')
|
||||||
await client.pin_message(chat, message, notify=True)
|
await client.pin_message(chat, message, notify=True)
|
||||||
"""
|
"""
|
||||||
|
return await self._pin(entity, message, unpin=False, notify=notify)
|
||||||
|
|
||||||
|
async def unpin_message(
|
||||||
|
self: 'TelegramClient',
|
||||||
|
entity: 'hints.EntityLike',
|
||||||
|
message: 'typing.Optional[hints.MessageIDLike]' = None,
|
||||||
|
*,
|
||||||
|
notify: bool = False
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Unpins a message in a chat.
|
||||||
|
|
||||||
|
If no message ID is specified, all pinned messages will be unpinned.
|
||||||
|
|
||||||
|
See also `Message.unpin() <telethon.tl.custom.message.Message.unpin>`.
|
||||||
|
|
||||||
|
Arguments
|
||||||
|
entity (`entity`):
|
||||||
|
The chat where the message should be pinned.
|
||||||
|
|
||||||
|
message (`int` | `Message <telethon.tl.custom.message.Message>`):
|
||||||
|
The message or the message ID to unpin. If it's
|
||||||
|
`None`, all messages will be unpinned instead.
|
||||||
|
|
||||||
|
Example
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Unpin all messages from a chat
|
||||||
|
await client.unpin_message(chat)
|
||||||
|
"""
|
||||||
|
return await self._pin(entity, message, unpin=True, notify=notify)
|
||||||
|
|
||||||
|
async def _pin(self, entity, message, *, unpin, notify=False):
|
||||||
message = utils.get_message_id(message) or 0
|
message = utils.get_message_id(message) or 0
|
||||||
entity = await self.get_input_entity(entity)
|
entity = await self.get_input_entity(entity)
|
||||||
|
if message <= 0: # old behaviour accepted negative IDs to unpin
|
||||||
|
await self(functions.messages.UnpinAllMessagesRequest(entity))
|
||||||
|
return
|
||||||
|
|
||||||
request = functions.messages.UpdatePinnedMessageRequest(
|
request = functions.messages.UpdatePinnedMessageRequest(
|
||||||
peer=entity,
|
peer=entity,
|
||||||
id=message,
|
id=message,
|
||||||
silent=not notify
|
silent=not notify,
|
||||||
|
unpin=unpin,
|
||||||
)
|
)
|
||||||
result = await self(request)
|
result = await self(request)
|
||||||
|
|
||||||
# Unpinning does not produce a service message, and technically
|
# Unpinning does not produce a service message
|
||||||
# users can pass negative IDs which seem to behave as unpinning too.
|
if unpin:
|
||||||
if message <= 0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Pinning in User chats (just with yourself really) does not produce a service message
|
# Pinning in User chats (just with yourself really) does not produce a service message
|
||||||
|
@ -1011,6 +1011,16 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
|||||||
return await self._client.pin_message(
|
return await self._client.pin_message(
|
||||||
await self.get_input_chat(), self.id, notify=notify)
|
await self.get_input_chat(), self.id, notify=notify)
|
||||||
|
|
||||||
|
async def unpin(self):
|
||||||
|
"""
|
||||||
|
Unpins the message. Shorthand for
|
||||||
|
`telethon.client.messages.MessageMethods.unpin_message`
|
||||||
|
with both ``entity`` and ``message`` already set.
|
||||||
|
"""
|
||||||
|
if self._client:
|
||||||
|
return await self._client.unpin_message(
|
||||||
|
await self.get_input_chat(), self.id)
|
||||||
|
|
||||||
# endregion Public Methods
|
# endregion Public Methods
|
||||||
|
|
||||||
# region Private Methods
|
# region Private Methods
|
||||||
|
Loading…
Reference in New Issue
Block a user