U
    h                     @   s>   d dl mZ ddl mZmZmZ ddl mZ G dd dZdS )	   )Draft   )TLObjecttypes	functions   )utilsc                   @   sL   e Zd ZdZdd Zdd ZdddZdd
dZdd Zdd Z	dd Z
dS )Dialoga	  
    Custom class that encapsulates a dialog (an open "conversation" with
    someone, a group or a channel) providing an abstraction to easily
    access the input version/normal entity/message etc. The library will
    return instances of this class when calling :meth:`.get_dialogs()`.

    Args:
        dialog (:tl:`Dialog`):
            The original ``Dialog`` instance.

        pinned (`bool`):
            Whether this dialog is pinned to the top or not.

        folder_id (`folder_id`):
            The folder ID that this dialog belongs to.

        archived (`bool`):
            Whether this dialog is archived or not (``folder_id is None``).

        message (`Message <telethon.tl.custom.message.Message>`):
            The last message sent on this dialog. Note that this member
            will not be updated when new messages arrive, it's only set
            on creation of the instance.

        date (`datetime`):
            The date of the last message sent on this dialog.

        entity (`entity`):
            The entity that belongs to this dialog (user, chat or channel).

        input_entity (:tl:`InputPeer`):
            Input version of the entity.

        id (`int`):
            The marked ID of the entity, which is guaranteed to be unique.

        name (`str`):
            Display name for this dialog. For chats and channels this is
            their title, and for users it's "First-Name Last-Name".

        title (`str`):
            Alias for `name`.

        unread_count (`int`):
            How many messages are currently unread in this dialog. Note that
            this value won't update when new messages arrive.

        unread_mentions_count (`int`):
            How many mentions are currently unread in this dialog. Note that
            this value won't update when new messages arrive.

        draft (`Draft <telethon.tl.custom.draft.Draft>`):
            The draft object in this dialog. It will not be `None`,
            so you can call ``draft.set_message(...)``.

        is_user (`bool`):
            `True` if the `entity` is a :tl:`User`.

        is_group (`bool`):
            `True` if the `entity` is a :tl:`Chat`
            or a :tl:`Channel` megagroup.

        is_channel (`bool`):
            `True` if the `entity` is a :tl:`Channel`.
    c                 C   s   || _ || _t|j| _|j| _|jd k	| _|| _t| jdd | _|t	
|j | _t	| j| _t	
| j| _t	| j | _| _|j| _|j| _t|| j| jj| _t| jtj| _t| jtjtjfpt| jtjo| jj| _t| jtj| _ d S )Ndate)!_clientdialogboolZpinned	folder_idZarchivedmessagegetattrr
   r   Zget_peer_idZpeerentityZget_input_peerinput_entityidZget_display_namenametitleZunread_countZunread_mentions_countr   draft
isinstancer   ZUserZis_userZChatZChatForbiddenZChannelZ	megagroupZis_groupZ
is_channel)selfclientr   entitiesr    r   =/tmp/pip-unpacked-wheel-c81u5j2r/telethon/tl/custom/dialog.py__init__H   s&    zDialog.__init__c                    s   | j j| jf||I dH S )z
        Sends a message to this dialog. This is just a wrapper around
        ``client.send_message(dialog.input_entity, *args, **kwargs)``.
        N)r   send_messager   )r   argskwargsr   r   r   r   c   s    zDialog.send_messageFc                    s   | j j| j|dI dH  dS )a  
        Deletes the dialog from your dialog list. If you own the
        channel this won't destroy it, only delete it from the list.

        Shorthand for `telethon.client.dialogs.DialogMethods.delete_dialog`
        with ``entity`` already set.
        )revokeN)r   Zdelete_dialogr   )r   r!   r   r   r   deletek   s    zDialog.deleter   c                    s&   |  tjtj| j|dgI dH S )a  
        Archives (or un-archives) this dialog.

        Args:
            folder (`int`, optional):
                The folder to which the dialog should be archived to.

                If you want to "un-archive" it, use ``folder=0``.

        Returns:
            The :tl:`Updates` object that the request produces.

        Example:

            .. code-block:: python

                # Archiving
                dialog.archive()

                # Un-archiving
                dialog.archive(0)
        )r   N)r   r   foldersZEditPeerFoldersRequestr   ZInputFolderPeerr   )r   folderr   r   r   archivex   s    
zDialog.archivec                 C   s   d| j | j| j| j| jdS )Nr	   )_r   r
   r   r   r   )r   r
   r   r   r   r   r   r   r   to_dict   s    zDialog.to_dictc                 C   s   t |  S )Nr   Zpretty_formatr(   r'   r   r   r   __str__   s    zDialog.__str__c                 C   s   t j|  ddS )N    )indentr)   r'   r   r   r   	stringify   s    zDialog.stringifyN)F)r   )__name__
__module____qualname____doc__r   r   r"   r%   r(   r*   r-   r   r   r   r   r	      s   A


r	   N) r   r   r   r   r   r	   r   r   r   r   <module>   s   