Skip to content

Commit 8ee5ea0

Browse files
committed
Update pin_chat_message to return Message instead of bool
1 parent 58eb10a commit 8ee5ea0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

pyrogram/methods/chats/pin_chat_message.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from typing import Union
2020

21-
from pyrogram import raw
21+
from pyrogram import raw, types
2222
from pyrogram.scaffold import Scaffold
2323

2424

@@ -29,7 +29,7 @@ async def pin_chat_message(
2929
message_id: int,
3030
disable_notification: bool = False,
3131
both_sides: bool = False,
32-
) -> bool:
32+
) -> "types.Message":
3333
"""Pin a message in a group, channel or your own chat.
3434
You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in
3535
the supergroup or "can_edit_messages" admin right in the channel.
@@ -50,7 +50,7 @@ async def pin_chat_message(
5050
Applicable to private chats only. Defaults to False.
5151
5252
Returns:
53-
``bool``: True on success.
53+
:obj:`~pyrogram.types.Message`: On success, the service message is returned.
5454
5555
Example:
5656
.. code-block:: python
@@ -61,7 +61,7 @@ async def pin_chat_message(
6161
# Pin without notification
6262
app.pin_chat_message(chat_id, message_id, disable_notification=True)
6363
"""
64-
await self.send(
64+
r = await self.send(
6565
raw.functions.messages.UpdatePinnedMessage(
6666
peer=await self.resolve_peer(chat_id),
6767
id=message_id,
@@ -70,4 +70,10 @@ async def pin_chat_message(
7070
)
7171
)
7272

73-
return True
73+
users = {u.id: u for u in r.users}
74+
chats = {c.id: c for c in r.chats}
75+
76+
for i in r.updates:
77+
if isinstance(i, (raw.types.UpdateNewMessage,
78+
raw.types.UpdateNewChannelMessage)):
79+
return await types.Message._parse(self, i.message, users, chats)

pyrogram/types/messages_and_media/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@ async def vote(
34233423
options=option
34243424
)
34253425

3426-
async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> bool:
3426+
async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> "types.Message":
34273427
"""Bound method *pin* of :obj:`~pyrogram.types.Message`.
34283428
34293429
Use as a shortcut for:
@@ -3450,7 +3450,7 @@ async def pin(self, disable_notification: bool = False, both_sides: bool = False
34503450
Applicable to private chats only. Defaults to False.
34513451
34523452
Returns:
3453-
True on success.
3453+
:obj:`~pyrogram.types.Message`: On success, the service message is returned.
34543454
34553455
Raises:
34563456
RPCError: In case of a Telegram RPC error.

0 commit comments

Comments
 (0)