1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
1919from asyncio import sleep
20+ from datetime import datetime
2021from typing import AsyncGenerator , Optional
2122
2223import pyrogram
@@ -28,7 +29,9 @@ async def get_dialogs(
2829 self : "pyrogram.Client" ,
2930 limit : int = 0 ,
3031 pinned_only : bool = False ,
31- chat_list : int = 0
32+ chat_list : int = 0 ,
33+ offset_date : datetime = utils .zero_datetime (),
34+ offset_message_id : int = 0 ,
3235 ) -> Optional [AsyncGenerator ["types.Dialog" , None ]]:
3336 """Get a user's dialogs sequentially.
3437
@@ -46,6 +49,12 @@ async def get_dialogs(
4649 chat_list (``int``, *optional*):
4750 Chat list from which to get the dialogs; Only Main (0) and Archive (1) chat lists are supported. Defaults to (0) Main chat list.
4851
52+ offset_date (:py:obj:`~datetime.datetime`, *optional*):
53+ The date starting from which the dialogs need to be fetched. Use 0 or any date in the future to get results from the last dialog.
54+
55+ offset_message_id (``int``, *optional*):
56+ The message identifier of the last message in the last found dialog, or 0 for the first request.
57+
4958 Returns:
5059 ``Generator``: A generator yielding :obj:`~pyrogram.types.Dialog` objects.
5160
@@ -60,8 +69,7 @@ async def get_dialogs(
6069 total = limit or (1 << 31 ) - 1
6170 request_limit = min (100 , total )
6271
63- offset_date = 0
64- offset_id = 0
72+ offset_date = utils .datetime_to_timestamp (offset_date )
6573 offset_peer = raw .types .InputPeerEmpty ()
6674
6775 seen_dialog_ids = set ()
@@ -70,7 +78,7 @@ async def get_dialogs(
7078 r = await self .invoke (
7179 raw .functions .messages .GetDialogs (
7280 offset_date = offset_date ,
73- offset_id = offset_id ,
81+ offset_id = offset_message_id ,
7482 offset_peer = offset_peer ,
7583 limit = request_limit ,
7684 hash = 0 ,
@@ -125,7 +133,7 @@ async def get_dialogs(
125133 if last .top_message is None :
126134 return
127135
128- offset_id = last .top_message .id
136+ offset_message_id = last .top_message .id
129137 offset_date = utils .datetime_to_timestamp (last .top_message .date )
130138 offset_peer = await self .resolve_peer (last .chat .id )
131139
0 commit comments