U
    ;g                      @   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  s\  d}|p
d}t d|}d}d}tj }| jtjjj||||ddddI dH }dd	 |jD }d
d	 |j	D }	i }
|jD ]<}t
|tjjrqzt|j}tj| |||	I dH |
|< qzg }|jD ].}t
|tjjsq|tj| ||
||	 q|sdS |d }|jj}t|jj}| |jjI dH }|D ]$}|V  |d7 }||kr0 dS q0q(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   b/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/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   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"   Zdialoglastr   r   r   get_dialogs   sP    




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   