o
    2g/                     @  s   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ er*dd	lZG d
d deZG dd deZG dd deZG dd deZd	S )zProvide models for new modmail.    )annotations)TYPE_CHECKINGAny   )API_PATH)_deprecate_argssnake_case_keys   )
RedditBaseNc                      s*   e Zd ZdZdZdZd
 fdd	Z  ZS )ModmailObjectz7A base class for objects within a modmail conversation.authorid	attributestrvaluer   c                   s*   || j kr| jj|}t || dS )z)Objectify the AUTHOR_ATTRIBUTE attribute.N)AUTHOR_ATTRIBUTE_reddit	_objector	objectifysuper__setattr__)selfr   r   	__class__ R/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/modmail.pyr      s   
zModmailObject.__setattr__)r   r   r   r   )__name__
__module____qualname____doc__r   	STR_FIELDr   __classcell__r   r   r   r   r      s
    r   c                      s  e Zd ZdZdZed=ddZed=d	d
Zed>ddZ				d?d@ fddZ
dAddZ fddZdd Zd d! Zd"d# Zed$d%d&dBd(d)Zeddd*dCd,d-Zed.d/d0ddd1dDd3d4Zd5d6 Zd7d8 Zd9d: Zeddd*dCd;d<Z  ZS )EModmailConversationa  A class for modmail conversations.

    .. include:: ../../typical_attributes.rst

    ==================== ===============================================================
    Attribute            Description
    ==================== ===============================================================
    ``authors``          Provides an ordered list of :class:`.Redditor` instances. The
                         authors of each message in the modmail conversation.
    ``id``               The ID of the :class:`.ModmailConversation`.
    ``is_highlighted``   Whether or not the :class:`.ModmailConversation` is
                         highlighted.
    ``is_internal``      Whether or not the :class:`.ModmailConversation` is a private
                         mod conversation.
    ``last_mod_update``  Time of the last mod message reply, represented in the `ISO
                         8601`_ standard with timezone.
    ``last_updated``     Time of the last message reply, represented in the `ISO 8601`_
                         standard with timezone.
    ``last_user_update`` Time of the last user message reply, represented in the `ISO
                         8601`_ standard with timezone.
    ``num_messages``     The number of messages in the :class:`.ModmailConversation`.
    ``obj_ids``          Provides a list of dictionaries representing mod actions on the
                         :class:`.ModmailConversation`. Each dict contains attributes of
                         ``"key"`` and ``"id"``. The key can be either ``""messages"``
                         or ``"ModAction"``. ``"ModAction"`` represents
                         archiving/highlighting etc.
    ``owner``            Provides an instance of :class:`.Subreddit`. The subreddit that
                         the :class:`.ModmailConversation` belongs to.
    ``participant``      Provides an instance of :class:`.Redditor`. The participating
                         user in the :class:`.ModmailConversation`.
    ``subject``          The subject of the :class:`.ModmailConversation`.
    ==================== ===============================================================

    .. _iso 8601: https://en.wikipedia.org/wiki/ISO_8601

    r   datadict[str, Any]redditpraw.Redditc                 C  sT   g g d}| d D ]}|d }| | |d  }||  |j| q	| | dS )z1Convert messages and mod actions to PRAW objects.)messages
modActionsobjIdskeyr   N)appendr   r   update)r#   r%   resultthingr*   
thing_datar   r   r   _convert_conversation_objectsD   s   
z1ModmailConversation._convert_conversation_objectsc                 C  s   |j j|jjd  t|j j|jjd  d}| D ]C\}}g }| |  D ]+\}}|||ddd d}|tur=|d= | D ]
\}	}
t||	|
 qA|| q&t	|d	d
 dd| |< qdS )z<Convert dictionaries of recent user history to PRAW objects.comment
submission)recentCommentsrecentConvosrecentPosts_r	   r   	permalinkc                 S  s   t | jddS )N$   )base)intr   )xr   r   r   <lambda>`   s    z;ModmailConversation._convert_user_summary.<locals>.<lambda>T)r*   reverseN)
r   parsersconfigkindsr"   itemsrsplitsetattrr+   sorted)r#   r%   r@   kindparserobjectsthing_idsummaryr.   r*   r   r   r   r   _convert_user_summaryN   s   z)ModmailConversation._convert_user_summaryreturnc                   sz    fdd|d D |d< dD ]} j || ||< q|dr3| |d    j |d |d< t|}|  |dS )zReturn an instance of :class:`.ModmailConversation` from ``data``.

        :param data: The structured data.
        :param reddit: An instance of :class:`.Reddit`.

        c                   s   g | ]} j |qS r   )r   r   ).0r   r%   r   r   
<listcomp>n   s    z-ModmailConversation.parse.<locals>.<listcomp>authors)ownerparticipantuser_data)r   r   getrL   r   )clsr#   r%   entityr   rO   r   parseb   s   


zModmailConversation.parseNF
str | None	mark_readboolrV   dict[str, Any] | Nonec                   sR   t |t |krd}t||r|| _t j||d |r$ddi| _dS d| _dS )zInitialize a :class:`.ModmailConversation` instance.

        :param mark_read: If ``True``, conversation is marked as read (default:
            ``False``).

        z(Either 'id' or '_data' must be provided.rU   markReadTN)r]   	TypeErrorr   r   __init___info_params)r   r%   r   r\   rV   msgr   r   r   ra   |   s   zModmailConversation.__init__other_conversationslist[ModmailConversation]r   c                 C  s"   | g|pg  }d dd |D S )z2Return a comma-separated list of conversation IDs.,c                 s  s    | ]}|j V  qd S Nr8   )rN   conversationr   r   r   	<genexpr>   s    z?ModmailConversation._build_conversation_list.<locals>.<genexpr>)join)r   rd   conversationsr   r   r   _build_conversation_list   s   z,ModmailConversation._build_conversation_listc                   s2   |   }| jj|}| j|j t   d S rg   )_fetch_datar   r   r   __dict__r,   r   _fetch)r   r#   otherr   r   r   ro      s   zModmailConversation._fetchc                 C  s   dd| j i| jfS )Nmodmail_conversationr   )r   rb   r   r   r   r   _fetch_info   s   zModmailConversation._fetch_infoc                 C     | j td j| jd dS )zArchive the conversation.

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").archive()

        modmail_archiver8   Nr   postr   formatr   rr   r   r   r   archive      
zModmailConversation.archivec                 C  rt   )zHighlight the conversation.

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").highlight()

        modmail_highlightr8   Nrv   rr   r   r   r   	highlight   rz   zModmailConversation.highlightnum_daysr   )r}   r<   c                C  s<   |dkr
d|d ini }| j jd|td j| jdd dS )	a  Mute the non-mod user associated with the conversation.

        :param num_days: Duration of mute in days. Valid options are ``3``, ``7``, or
            ``28`` (default: ``3``).

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").mute()

        To mute for 7 days:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").mute(num_days=7)

        r   	num_hours   POSTmodmail_muter8   )methodparamspathNr   requestr   rx   r   )r   r}   r   r   r   r   mute   s   
zModmailConversation.mute)rd    list[ModmailConversation] | Nonec                C  &   d|  |i}| jjtd |d dS )a  Mark the conversation(s) as read.

        :param other_conversations: A list of other conversations to mark (default:
            ``None``).

        For example, to mark the conversation as read along with other recent
        conversations from the same user:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            conversation = subreddit.modmail.conversation("2gmz")
            conversation.read(other_conversations=conversation.user.recent_convos)

        conversationIdsmodmail_readr#   Nrl   r   rw   r   r   rd   r#   r   r   r   read      zModmailConversation.readbodyauthor_hiddeninternal)r   r   ModmailMessagec          	      C  s   |||d}| j jtd j| jd|d}t|tr1|d d d d }|d	 | }| j j|S |j	D ]}|j|j
d d krD|  S q4d
S )a[  Reply to the conversation.

        :param author_hidden: When ``True``, author is hidden from non-moderators
            (default: ``False``).
        :param body: The Markdown formatted content for a message.
        :param internal: When ``True``, message is a private moderator note, hidden from
            non-moderators (default: ``False``).

        :returns: A :class:`.ModmailMessage` object for the newly created message.

        For example, to reply to the non-mod user while hiding your username:

        .. code-block:: python

            conversation = reddit.subreddit("test").modmail("2gmz")
            conversation.reply(body="Message body", author_hidden=True)

        To create a private moderator note on the conversation:

        .. code-block:: python

            conversation.reply(body="Message body", internal=True)

        )r   isAuthorHidden
isInternalrq   r8   r   rh   r)   r7   r   r'   N)r   rw   r   rx   r   
isinstancedictr   r   r'   obj_ids)	r   r   r   r   r#   response
message_idmessage_datamessager   r   r   reply   s    

zModmailConversation.replyc                 C  rt   )zUnarchive the conversation.

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").unarchive()

        modmail_unarchiver8   Nrv   rr   r   r   r   	unarchive  rz   zModmailConversation.unarchivec                 C  rt   )zUn-highlight the conversation.

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").unhighlight()

        r{   r8   N)r   deleter   rx   r   rr   r   r   r   unhighlight$  rz   zModmailConversation.unhighlightc                 C  s"   | j jdtd j| jdd dS )zUnmute the non-mod user associated with the conversation.

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz").unmute()

        r   modmail_unmuter8   )r   r   Nr   rr   r   r   r   unmute0  s   

zModmailConversation.unmutec                C  r   )a  Mark the conversation(s) as unread.

        :param other_conversations: A list of other conversations to mark (default:
            ``None``).

        For example, to mark the conversation as unread along with other recent
        conversations from the same user:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            conversation = subreddit.modmail.conversation("2gmz")
            conversation.unread(other_conversations=conversation.user.recent_convos)

        r   modmail_unreadr   Nr   r   r   r   r   unread>  r   zModmailConversation.unread)r#   r$   r%   r&   )r#   r$   r%   r&   rM   r"   )NFN)r%   r&   r   r[   r\   r]   rV   r^   )rd   re   rM   r   )r}   r<   )rd   r   )r   r]   r   r   r   r]   rM   r   )r   r   r   r   r    staticmethodr0   rL   classmethodrZ   ra   rl   ro   rs   ry   r|   r   r   r   r   r   r   r   r   r!   r   r   r   r   r"      s<    %	

,r"   c                   @     e Zd ZdZdS )ModmailActionz7A class for moderator actions on modmail conversations.Nr   r   r   r   r   r   r   r   r   S      r   c                   @  r   )r   zA class for modmail messages.Nr   r   r   r   r   r   W  r   r   )r   
__future__r   typingr   r   constr   utilr   r   r;   r
   prawr   r"   r   r   r   r   r   r   <module>   s      9