2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +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 pyrogram import raw
from pyrogram import raw, types
from pyrogram.scaffold import Scaffold
@ -29,7 +29,7 @@ class PinChatMessage(Scaffold):
message_id: int,
disable_notification: bool = False,
both_sides: bool = False,
) -> bool:
) -> "types.Message":
"""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
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.
Returns:
``bool``: True on success.
:obj:`~pyrogram.types.Message`: On success, the service message is returned.
Example:
.. code-block:: python
@ -61,7 +61,7 @@ class PinChatMessage(Scaffold):
# Pin without notification
app.pin_chat_message(chat_id, message_id, disable_notification=True)
"""
await self.send(
r = await self.send(
raw.functions.messages.UpdatePinnedMessage(
peer=await self.resolve_peer(chat_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
)
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`.
Use as a shortcut for:
@ -3450,7 +3450,7 @@ class Message(Object, Update):
Applicable to private chats only. Defaults to False.
Returns:
True on success.
:obj:`~pyrogram.types.Message`: On success, the service message is returned.
Raises:
RPCError: In case of a Telegram RPC error.