From 357253b63e02ca923197a9fd98bdeb1d0948ced2 Mon Sep 17 00:00:00 2001 From: YoilyL Date: Sun, 1 Jul 2018 21:34:05 +0300 Subject: [PATCH] added option to reverse get_history order added an argument `reverse` to get_history which if set to True returns the messages from first to last instead of from newest to oldest. --- pyrogram/client/methods/messages/get_history.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py index 4089dde9..f55a64ed 100644 --- a/pyrogram/client/methods/messages/get_history.py +++ b/pyrogram/client/methods/messages/get_history.py @@ -27,7 +27,8 @@ class GetHistory(BaseClient): offset: int = 0, limit: int = 100, offset_id: int = 0, - offset_date: int = 0): + offset_date: int = 0, + reverse: bool = False): """Use this method to retrieve the history of a chat. You can get up to 100 messages at once. @@ -52,6 +53,9 @@ class GetHistory(BaseClient): offset_date (``int``, *optional*): Pass a date in Unix time as offset to retrieve only older messages starting from that date. + + reverse (``bool``, *optional*): + get the messages in order from first to last (instead of newest to oldest). Returns: On success, a :obj:`Messages ` object is returned. @@ -59,7 +63,9 @@ class GetHistory(BaseClient): Raises: :class:`Error ` """ - + if reverse: + offset = -limit*(offset + 1) + if offset_id: offset_id +=1 r = self.send( functions.messages.GetHistory( peer=self.resolve_peer(chat_id), @@ -107,5 +113,5 @@ class GetHistory(BaseClient): return pyrogram.Messages( total_count=getattr(r, "count", len(r.messages)), - messages=messages + messages=messages if not reverse else messages[::-1] )