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	 ddl
mZmZmZ dd	lmZ dd
lmZ er8ddlZG dd deeee	ZG dd deZdS )zProvide the Message class.    )annotations)TYPE_CHECKINGAny   )API_PATH   )
RedditBase)FullnameMixinInboxableMixinReplyableMixin)Redditor)	SubredditNc                      sh   e Zd ZdZdZedd	d
ZedddZedddZ	e	j
dddZ	d fddZdd Z  ZS )Messagea  A class for private messages.

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

    =============== ================================================================
    Attribute       Description
    =============== ================================================================
    ``author``      Provides an instance of :class:`.Redditor`.
    ``body``        The body of the message, as Markdown.
    ``body_html``   The body of the message, as HTML.
    ``created_utc`` Time the message was created, represented in `Unix Time`_.
    ``dest``        Provides an instance of :class:`.Redditor`. The recipient of the
                    message.
    ``id``          The ID of the message.
    ``name``        The full ID of the message, prefixed with ``t4_``.
    ``subject``     The subject of the message.
    ``was_comment`` Whether or not the message was a comment reply.
    =============== ================================================================

    .. _unix time: https://en.wikipedia.org/wiki/Unix_time

    iddatadict[str, Any]redditpraw.RedditreturnMessage | SubredditMessagec                 C  s   |d rt ||d |d< |d dr"t||d dd |d< n	t ||d |d< |d r@|d }|j|d d |d< ng |d< |d	 rWt||d	 |d	< t||d
S | ||d
S )zReturn an instance of :class:`.Message` or :class:`.SubredditMessage` from ``data``.

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

        authordest#r   Nrepliesr   children	subreddit)_data)r   
startswithr   	_objector	objectifySubredditMessage)clsr   r   r    r"   R/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/message.pyparse+   s   
zMessage.parsestrc                 C  s   | j jjd S )zReturn the class's kind.message)_redditconfigkindsselfr"   r"   r#   _kindI   s   zMessage._kindpraw.models.Message | Nonec                 C  s.   | j s| jr| jj| jdd | _ | j S )z.Return the parent of the message if it exists._r   )_parent	parent_idr'   inboxr&   splitr*   r"   r"   r#   parentN   s   zMessage.parentvaluec                 C  s
   || _ d S )N)r/   )r+   r4   r"   r"   r#   r3   U   s   
r   c                   s@   t  j||dd d| _|dg D ]}|j| jkr| |_qdS )z(Initialize a :class:`.Message` instance.T)r   _fetchedNr   )super__init__r/   getr0   fullnamer3   )r+   r   r   reply	__class__r"   r#   r7   Y   s   zMessage.__init__c                 C     | j jtd d| jid dS )a<  Delete the message.

        .. note::

            Reddit does not return an indication of whether or not the message was
            successfully deleted.

        For example, to delete the most recent message in your inbox:

        .. code-block:: python

            next(reddit.inbox.all()).delete()

        delete_messager   r   Nr'   postr   r9   r*   r"   r"   r#   deletea   s   zMessage.delete)r   r   r   r   r   r   )r   r%   )r   r-   )r4   r-   )r   r   r   r   )__name__
__module____qualname____doc__	STR_FIELDclassmethodr$   propertyr,   r3   setterr7   rB   __classcell__r"   r"   r;   r#   r      s    r   c                   @  s    e Zd ZdZdd Zdd ZdS )r    a  A class for messages to a subreddit.

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

    =============== =================================================================
    Attribute       Description
    =============== =================================================================
    ``author``      Provides an instance of :class:`.Redditor`.
    ``body``        The body of the message, as Markdown.
    ``body_html``   The body of the message, as HTML.
    ``created_utc`` Time the message was created, represented in `Unix Time`_.
    ``dest``        Provides an instance of :class:`.Redditor`. The recipient of the
                    message.
    ``id``          The ID of the message.
    ``name``        The full ID of the message, prefixed with ``t4_``.
    ``subject``     The subject of the message.
    ``subreddit``   If the message was sent from a subreddit, provides an instance of
                    :class:`.Subreddit`.
    ``was_comment`` Whether or not the message was a comment reply.
    =============== =================================================================

    .. _unix time: https://en.wikipedia.org/wiki/Unix_time

    c                 C  r=   )a  Mute the sender of this :class:`.SubredditMessage`.

        For example, to mute the sender of the first :class:`.SubredditMessage` in the
        authenticated users' inbox:

        .. code-block:: python

            from praw.models import SubredditMessage

            msg = next(
                message for message in reddit.inbox.all() if isinstance(message, SubredditMessage)
            )
            msg.mute()

        mute_senderr   r?   Nr@   r*   r"   r"   r#   mute      zSubredditMessage.mutec                 C  r=   )a  Unmute the sender of this :class:`.SubredditMessage`.

        For example, to unmute the sender of the first :class:`.SubredditMessage` in the
        authenticated users' inbox:

        .. code-block:: python

            from praw.models import SubredditMessage

            msg = next(
                message for message in reddit.inbox.all() if isinstance(message, SubredditMessage)
            )
            msg.unmute()

        unmute_senderr   r?   Nr@   r*   r"   r"   r#   unmute   rN   zSubredditMessage.unmuteN)rC   rD   rE   rF   rM   rP   r"   r"   r"   r#   r    s   s    r    )rF   
__future__r   typingr   r   constr   baser   mixinsr	   r
   r   redditorr   r   r   praw.modelsprawr   r    r"   r"   r"   r#   <module>   s    b