B
    fd                  @   s>   d dl mZmZ d dlZd dlmZmZmZ G dd dZdS )    )AsyncGeneratorOptionalN)typesrawutilsc               @   s(   e Zd Zddeeed  dddZdS )	
GetDialogsr   zpyrogram.Client)ztypes.DialogN)selflimitreturnc          
   C  sn  d}|p
d}t d|}d}d}tj }x>| jtjjj||||ddddI dH }dd	 |jD }d
d	 |j	D }	i }
xF|jD ]<}t
|tjjrqt|j}tj| |||	I dH |
|< qW g }x8|jD ].}t
|tjjsq|tj| ||
||	 qW |sdS |d }|jj}t|jj}| |jjI dH }x*|D ]"}|V  |d7 }||kr@dS q@W q,W dS )au  Get a user's dialogs sequentially.

        .. include:: /_includes/usable-by/users.rst

        Parameters:
            limit (``int``, *optional*):
                Limits the number of dialogs to be retrieved.
                By default, no limit is applied and all dialogs are returned.

        Returns:
            ``Generator``: A generator yielding :obj:`~pyrogram.types.Dialog` objects.

        Example:
            .. code-block:: python

                # Iterate through all dialogs
                async for dialog in app.get_dialogs():
                    print(dialog.chat.first_name or dialog.chat.title)
        r   id   )offset_date	offset_idoffset_peerr	   hash<   )Zsleep_thresholdNc             S   s   i | ]}||j qS  )id).0ir   r   F/tmp/pip-unpacked-wheel-rcokkf2l/pyrogram/methods/chats/get_dialogs.py
<dictcomp>E   s    z*GetDialogs.get_dialogs.<locals>.<dictcomp>c             S   s   i | ]}||j qS r   )r   )r   r   r   r   r   r   F   s       )minr   r   ZInputPeerEmptyZinvokeZ	functionsmessagesr   userschats
isinstanceZMessageEmptyr   Zget_peer_idZpeer_idMessage_parsedialogsDialogappendZtop_messager   Zdatetime_to_timestampdateZresolve_peerZchat)r   r	   currenttotalr   r   r   rr   r   r   messageZchat_idr    dialoglastr   r   r   get_dialogs   sN    

 

zGetDialogs.get_dialogsN)r   )__name__
__module____qualname__intr   r   r*   r   r   r   r   r      s   r   )typingr   r   Zpyrogramr   r   r   r   r   r   r   r   <module>   s   