Ë
    Fü´j;!  ã                  ó„   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ erddlmZ dd	lmZ  G d
„ d«      Zy)zProvide the Modmail class.é    )Úannotations)ÚTYPE_CHECKINGÚAny)ÚAPI_PATH)ÚListingGenerator)Ú
RedditBase)ÚModmailConversation)ÚIterator)Úmodelsc                  óž   — e Zd ZdZdddœdd„Zdd„Zdd„Zdddœ	 	 	 	 	 dd	„Zdddd
œ	 	 	 	 	 	 	 	 	 dd„Zddœ	 	 	 	 	 	 	 	 	 dd„Z	dd„Z
dd„Zy)ÚModmaila@  Provides modmail functions for a :class:`.Subreddit`.

    For example, to send a new modmail from r/test to u/spez with the subject ``"test"``
    along with a message body of ``"hello"``:

    .. code-block:: python

        reddit.subreddit("test").modmail.create(subject="test", body="hello", recipient="spez")

    NF)Ú	mark_readc               óF   — t        | j                  j                  ||¬«      S )a‰  Return an individual conversation.

        :param id: A reddit base36 conversation ID, e.g., ``"2gmz"``.
        :param mark_read: If ``True``, conversation is marked as read (default:
            ``False``).

        For example:

        .. code-block:: python

            reddit.subreddit("test").modmail("2gmz", mark_read=True)

        To print all messages from a conversation as Markdown source:

        .. code-block:: python

            conversation = reddit.subreddit("test").modmail("2gmz", mark_read=True)
            for message in conversation.messages:
                print(message.body_markdown)

        ``ModmailConversation.user`` is a special instance of :class:`.Redditor` with
        extra attributes describing the non-moderator user's recent posts, comments, and
        modmail messages within the subreddit, as well as information on active bans and
        mutes. This attribute does not exist on internal moderator discussions.

        For example, to print the user's ban status:

        .. code-block:: python

            conversation = reddit.subreddit("test").modmail("2gmz", mark_read=True)
            print(conversation.user.ban_status)

        To print a list of recent submissions by the user:

        .. code-block:: python

            conversation = reddit.subreddit("test").modmail("2gmz", mark_read=True)
            print(conversation.user.recent_posts)

        )Úidr   )r	   Ú	subredditÚ_reddit)Úselfr   r   s      úb/root/workspace/ytshorts/venv/lib/python3.12/site-packages/praw/models/reddit/subreddit/modmail.pyÚ__call__zModmail.__call__   s   € ôR # 4§>¡>×#9Ñ#9¸bÈIÔVÐVó    c                ó   — || _         y)z(Initialize a :class:`.Modmail` instance.N)r   )r   r   s     r   Ú__init__zModmail.__init__I   s	   € à"ˆ�r   c                óZ   — | j                   g|xs g z   }dj                  d„ |D «       «      S )z9Return a comma-separated list of subreddit display names.ú,c              3  ó2   K  — | ]  }t        |«      –— Œ y ­w©N)Ústr)Ú.0r   s     r   ú	<genexpr>z0Modmail._build_subreddit_list.<locals>.<genexpr>P   s   è ø€ ÒC¨9œ˜IŸÑCùs   ‚)r   Újoin)r   Úother_subredditsÚ
subredditss      r   Ú_build_subreddit_listzModmail._build_subreddit_listM   s.   € à—n‘nÐ%Ð)9Ò)?¸RÑ@ˆ
Ø�x‰xÑC¸
ÔCÓCÐCr   )r!   Ústatec               óÎ   — d| j                  |«      i}|r||d<   | j                  j                  j                  t        d   |¬«      }|d   D �cg c]
  } | |«      ‘Œ c}S c c}w )a%  Mark conversations for subreddit(s) as read.

        .. note::

            Due to server-side restrictions, r/all is not a valid subreddit for this
            method. Instead, use :meth:`~.Modmail.subreddits` to get a list of
            subreddits using the new modmail.

        :param other_subreddits: A list of :class:`.Subreddit` instances for which to
            mark conversations (default: ``None``).
        :param state: Can be one of: ``"all"``, ``"archived"``, or ``"highlighted"``,
            ``"inprogress"``, ``"join_requests"``, ``"mod"``, ``"new"``,
            ``"notifications"``, or ``"appeals"`` (default: ``"all"``). ``"all"`` does
            not include internal, archived, or appeals conversations.

        :returns: A list of :class:`.ModmailConversation` instances that were marked
            read.

        For example, to mark all notifications for a subreddit as read:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            subreddit.modmail.bulk_read(state="notifications")

        Úentityr$   Úmodmail_bulk_read)ÚparamsÚconversation_ids)r#   r   r   Úpostr   )r   r!   r$   r(   ÚresponseÚconversation_ids         r   Ú	bulk_readzModmail.bulk_readR   sl   € ð@ )1°$×2LÑ2LÐM]Ó2^Ð'_ˆÙØ#ˆF�7‰OØ—>‘>×)Ñ)×.Ñ.¬xÐ8KÑ/LÐU[Ð.Ó\ˆØ=EÐFXÑ=YÖZ¨/‘�_Õ%ÒZÐZùÒZs   ÁA")r!   Úsortr$   c               óÐ   — i }| j                   dk7  r| j                  |«      |d<   t        j                  d|d||dœ|¤Ž t	        | j                   j
                  t        d   fi |¤ŽS )a‰  Generate :class:`.ModmailConversation` objects for subreddit(s).

        :param other_subreddits: A list of :class:`.Subreddit` instances for which to
            fetch conversations (default: ``None``).
        :param sort: Can be one of: ``"mod"``, ``"recent"``, ``"unread"``, or ``"user"``
            (default: ``"recent"``).
        :param state: Can be one of: ``"all"``, ``"archived"``, ``"highlighted"``,
            ``"inprogress"``, ``"join_requests"``, ``"mod"``, ``"new"``,
            ``"notifications"``, or ``"appeals"`` (default: ``"all"``). ``"all"`` does
            not include internal, archived, or appeals conversations.

        Additional keyword arguments are passed in the initialization of
        :class:`.ListingGenerator`.

        For example:

        .. code-block:: python

            conversations = reddit.subreddit("all").modmail.conversations(state="mod")

        Úallr&   r(   )Ú	argumentsÚkeyr.   r$   Úmodmail_conversations© )r   r#   r   Ú_safely_add_argumentsr   r   r   )r   r!   r.   r$   Úgenerator_kwargsr(   s         r   ÚconversationszModmail.conversationsx   sx   € ð: ˆØ�>‰>˜UÒ"Ø#×9Ñ9Ð:JÓKˆF�8ÑÜ×(Ñ(ÐtÐ3CÈÐX\ÐdiÑtÐmsÒtÜØ�N‰N×"Ñ"ÜÐ,Ñ-ñ
ð ñ
ð 	
r   )Úauthor_hiddenc               ó‚   — ||| j                   ||dœ}| j                   j                  j                  t        d   |¬«      S )aÊ  Create a new :class:`.ModmailConversation`.

        :param author_hidden: When ``True``, author is hidden from non-moderators
            (default: ``False``).
        :param body: The message body. Cannot be empty.
        :param recipient: The recipient; a username or an instance of
            :class:`.Redditor`.
        :param subject: The message subject. Cannot be empty.

        :returns: A :class:`.ModmailConversation` object for the newly created
            conversation.

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            redditor = reddit.redditor("bboe")
            subreddit.modmail.create(subject="Subject", body="Body", recipient=redditor)

        )ÚbodyÚisAuthorHiddenÚsrNameÚsubjectÚtor3   )Údata)r   r   r*   r   )r   r8   r:   Ú	recipientr=   r?   s         r   ÚcreatezModmail.createŸ   sG   € ð8 Ø+Ø—n‘nØØñ
ˆð �~‰~×%Ñ%×*Ñ*¬8Ð4KÑ+LÐSWÐ*ÓXÐXr   c              #  ó   K  — | j                   j                  j                  t        d   «      }|d   j	                  «       D ]8  }| j                   j                  j                  |d   «      }|d   |_        |–— Œ: y­w)zÆYield subreddits using the new modmail that the user moderates.

        For example:

        .. code-block:: python

            subreddits = reddit.subreddit("all").modmail.subreddits()

        Úmodmail_subredditsr"   Údisplay_nameÚlastUpdatedN)r   r   Úgetr   ÚvaluesÚlast_updated)r   r+   Úvaluer   s       r   r"   zModmail.subredditsÃ   sv   è ø€ ð —>‘>×)Ñ)×-Ñ-¬hÐ7KÑ.LÓMˆØ˜lÑ+×2Ñ2Ó4ò 	ˆEØŸ™×.Ñ.×8Ñ8¸¸~Ñ9NÓOˆIØ%*¨=Ñ%9ˆIÔ"Ø‹Oñ	ùs   ‚A<A>c                óZ   — | j                   j                  j                  t        d   «      S )aS  Return unread conversation count by conversation state.

        At time of writing, possible states are: ``"archived"``, ``"highlighted"``,
        ``"inprogress"``, ``"join_requests"``, ``"mod"``, ``"new"``,
        ``"notifications"``, or ``"appeals"``.

        :returns: A dict mapping conversation states to unread counts.

        For example, to print the count of unread moderator discussions:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            unread_counts = subreddit.modmail.unread_count()
            print(unread_counts["mod"])

        Úmodmail_unread_count)r   r   rF   r   )r   s    r   Úunread_countzModmail.unread_countÓ   s%   € ð$ �~‰~×%Ñ%×)Ñ)¬(Ð3IÑ*JÓKÐKr   r   )r   ú
str | Noner   ÚboolÚreturnr	   )r   zmodels.SubredditrO   ÚNone)r!   ú#list[models.Subreddit | str] | NonerO   r   )r!   rQ   r$   rM   rO   zlist[ModmailConversation])
r!   rQ   r.   rM   r$   rM   r6   r   rO   zIterator[ModmailConversation])
r8   rN   r:   r   r@   zstr | models.Redditorr=   r   rO   r	   )rO   zIterator[models.Subreddit])rO   zdict[str, int])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r-   r7   rA   r"   rL   r4   r   r   r   r      sæ   „ ñ	ð)WÀ5õ )WóV#óDð AEØ ñ	$[ð >ð$[ð ð	$[ð
 
#ó$[ðR AEØØ ñ%
ð >ð%
ð ð	%
ð
 ð%
ð  ð%
ð 
'ó%
ðT $ñ"Yð ð"Yð ð	"Yð
 )ð"Yð ð"Yð 
ó"YóHô Lr   r   N)rU   Ú
__future__r   Útypingr   r   Ú
praw.constr   Úpraw.models.listing.generatorr   Úpraw.models.reddit.baser   Úpraw.models.reddit.modmailr	   Úcollections.abcr
   Úprawr   r   r4   r   r   ú<module>r^      s1   ðÙ  å "ç %å Ý :Ý .Ý :áÝ(å÷SLò SLr   