Return produced service message with pin_message

Fixes #1394.
This commit is contained in:
Lonami Exo 2020-04-29 10:29:14 +02:00
parent 74bced75b4
commit c43e2a0a3a
4 changed files with 25 additions and 5 deletions

View File

@ -131,7 +131,14 @@ class MessageParseMethods:
elif isinstance(update, (
types.UpdateNewChannelMessage, types.UpdateNewMessage)):
update.message._finish_init(self, entities, input_chat)
id_to_message[update.message.id] = update.message
# Pinning a message with `updatePinnedMessage` seems to
# always produce a service message we can't map so return
# it directly.
if hasattr(request, 'random_id'):
id_to_message[update.message.id] = update.message
else:
return update.message
elif (isinstance(update, types.UpdateEditMessage)
and helpers._entity_type(request.peer) != helpers._EntityType.CHANNEL):

View File

@ -1246,11 +1246,24 @@ class MessageMethods:
"""
message = utils.get_message_id(message) or 0
entity = await self.get_input_entity(entity)
await self(functions.messages.UpdatePinnedMessageRequest(
request = functions.messages.UpdatePinnedMessageRequest(
peer=entity,
id=message,
silent=not notify
))
)
result = await self(request)
# Unpinning does not produce a service message, and technically
# users can pass negative IDs which seem to behave as unpinning too.
if message <= 0:
return
# Pinning in User chats (just with yourself really) does not produce a service message
if helpers._entity_type(entity) == helpers._EntityType.USER:
return
# Pinning a message that doesn't exist would RPC-error earlier
return self._get_response_message(request, result, entity)
# endregion

View File

@ -259,7 +259,7 @@ class Album(EventBuilder):
`telethon.client.messages.MessageMethods.pin_message`
with both ``entity`` and ``message`` already set.
"""
await self.messages[0].pin(notify=notify)
return await self.messages[0].pin(notify=notify)
def __len__(self):
"""

View File

@ -898,7 +898,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
# maybe just make it illegal to call messages from raw API?
# That or figure out a way to always set it directly.
if self._client:
await self._client.pin_message(
return await self._client.pin_message(
await self.get_input_chat(), self.id, notify=notify)
# endregion Public Methods