Regression fix: limit replies to 1 (Closes #61)

This commit is contained in:
Dan 2018-04-26 10:50:30 +02:00
parent 0ed38518e1
commit 4cb7733821
2 changed files with 23 additions and 10 deletions

View File

@ -3348,7 +3348,8 @@ class Client:
def get_messages(self,
chat_id: int or str,
message_ids: list or int):
message_ids: list or int,
replies: int = 1):
"""Use this method to get messages that belong to a specific chat.
You can retrieve up to 200 messages at once.
@ -3362,6 +3363,9 @@ class Client:
message_ids (``list`` | ``int``):
A list of Message identifiers in the chat specified in *chat_id* or a single message id, as integer.
replies (``int``, optional):
The number of replies to get for each message. Defaults to 1.
Returns:
On success and in case *message_ids* was a list, the returned value will be a list of the requested
:obj:`Messages <pyrogram.api.types.pyrogram.Message>` even if a list contains just one element, otherwise if
@ -3395,12 +3399,23 @@ class Client:
for i in r.messages:
if isinstance(i, types.Message):
parser = message_parser.parse_message
messages.append(
message_parser.parse_message(
self, i, users, chats,
replies=replies
)
)
elif isinstance(i, types.MessageService):
parser = message_parser.parse_message_service
messages.append(
message_parser.parse_message_service(
self, i, users, chats
)
)
else:
parser = message_parser.parse_message_empty
messages.append(parser(self, i, users, chats))
messages.append(
message_parser.parse_message_empty(
self, i
)
)
return messages if is_list else messages[0]

View File

@ -480,7 +480,7 @@ def parse_message(
)
if message.reply_to_msg_id and replies:
m.reply_to_message = client.get_messages(m.chat.id, message.reply_to_msg_id)
m.reply_to_message = client.get_messages(m.chat.id, message.reply_to_msg_id, replies=replies - 1)
m.reply_to_message = m.reply_to_message
return m
@ -588,8 +588,6 @@ def parse_message_service(
def parse_message_empty(
client,
message: types.MessageEmpty,
users: dict,
chats: dict
message: types.MessageEmpty
) -> pyrogram_types.Message:
return pyrogram_types.Message(message_id=message.id)