2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Update pin_chat_message to return Message instead of bool

This commit is contained in:
Dan 2022-03-19 20:57:17 +01:00
parent 58eb10a676
commit 8ee5ea02b1
2 changed files with 13 additions and 7 deletions

View File

@ -18,7 +18,7 @@
from typing import Union from typing import Union
from pyrogram import raw from pyrogram import raw, types
from pyrogram.scaffold import Scaffold from pyrogram.scaffold import Scaffold
@ -29,7 +29,7 @@ class PinChatMessage(Scaffold):
message_id: int, message_id: int,
disable_notification: bool = False, disable_notification: bool = False,
both_sides: bool = False, both_sides: bool = False,
) -> bool: ) -> "types.Message":
"""Pin a message in a group, channel or your own chat. """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 You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in
the supergroup or "can_edit_messages" admin right in the channel. the supergroup or "can_edit_messages" admin right in the channel.
@ -50,7 +50,7 @@ class PinChatMessage(Scaffold):
Applicable to private chats only. Defaults to False. Applicable to private chats only. Defaults to False.
Returns: Returns:
``bool``: True on success. :obj:`~pyrogram.types.Message`: On success, the service message is returned.
Example: Example:
.. code-block:: python .. code-block:: python
@ -61,7 +61,7 @@ class PinChatMessage(Scaffold):
# Pin without notification # Pin without notification
app.pin_chat_message(chat_id, message_id, disable_notification=True) app.pin_chat_message(chat_id, message_id, disable_notification=True)
""" """
await self.send( r = await self.send(
raw.functions.messages.UpdatePinnedMessage( raw.functions.messages.UpdatePinnedMessage(
peer=await self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
id=message_id, id=message_id,
@ -70,4 +70,10 @@ class PinChatMessage(Scaffold):
) )
) )
return True users = {u.id: u for u in r.users}
chats = {c.id: c for c in r.chats}
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage)):
return await types.Message._parse(self, i.message, users, chats)

View File

@ -3423,7 +3423,7 @@ class Message(Object, Update):
options=option options=option
) )
async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> bool: async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> "types.Message":
"""Bound method *pin* of :obj:`~pyrogram.types.Message`. """Bound method *pin* of :obj:`~pyrogram.types.Message`.
Use as a shortcut for: Use as a shortcut for:
@ -3450,7 +3450,7 @@ class Message(Object, Update):
Applicable to private chats only. Defaults to False. Applicable to private chats only. Defaults to False.
Returns: Returns:
True on success. :obj:`~pyrogram.types.Message`: On success, the service message is returned.
Raises: Raises:
RPCError: In case of a Telegram RPC error. RPCError: In case of a Telegram RPC error.