Skip to content

Commit

Permalink
Merge 8e3d777 into c961c89
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeNetwork committed Jun 18, 2021
2 parents c961c89 + 8e3d777 commit c5f1540
Show file tree
Hide file tree
Showing 10 changed files with 1,269 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,11 @@ PRAW follows `semantic versioning <http://semver.org/>`_.
Unreleased
----------

**Added**

- :meth:`.Inbox.mark_all_read` to mark all messages as read with one API call.
- :meth:`.InboxableMixin.unblock_subreddit` to unblock a subreddit.

7.3.0 (2021/06/17)
------------------

Expand Down
3 changes: 2 additions & 1 deletion docs/code_overview/other.rst
Expand Up @@ -39,8 +39,9 @@ them bound to an attribute of one of the PRAW models.

other/commentmoderation
other/fullnamemixin
other/submissionmoderation
other/inboxablemixin
other/rulemoderation
other/submissionmoderation
other/subredditmoderation
other/subredditrulesmoderation
other/subredditwidgetsmoderation
Expand Down
5 changes: 5 additions & 0 deletions docs/code_overview/other/inboxablemixin.rst
@@ -0,0 +1,5 @@
InboxableMixin
==============

.. autoclass:: praw.models.reddit.mixins.InboxableMixin
:inherited-members:
2 changes: 2 additions & 0 deletions praw/endpoints.py
Expand Up @@ -137,6 +137,7 @@
"preferences": "api/v1/me/prefs",
"quarantine_opt_in": "api/quarantine_optin",
"quarantine_opt_out": "api/quarantine_optout",
"read_all_messages": "api/read_all_messages",
"read_message": "api/read_message/",
"removal_comment_message": "api/v1/modactions/removal_comment_message",
"removal_link_message": "api/v1/modactions/removal_link_message",
Expand Down Expand Up @@ -187,6 +188,7 @@
"suggested_sort": "api/set_suggested_sort/",
"trophies": "api/v1/user/{user}/trophies",
"trusted": "prefs/trusted",
"unblock_subreddit": "api/unblock_subreddit",
"uncollapse": "api/uncollapse_message/",
"unfriend": "r/{subreddit}/api/unfriend/",
"unhide": "api/unhide/",
Expand Down
17 changes: 17 additions & 0 deletions praw/models/inbox.py
Expand Up @@ -80,6 +80,23 @@ def comment_replies(
self._reddit, API_PATH["comment_replies"], **generator_kwargs
)

def mark_all_read(self):
"""Mark all messages as read with just one API call.
Example usage:
.. code-block:: python
reddit.inbox.mark_all_read()
.. note::
This method returns after Reddit acknowleges your request, instead of after
the request has been fulfilled.
"""
self._reddit.post(API_PATH["read_all_messages"])

def mark_read(
self, items: List[Union["praw.models.Comment", "praw.models.Message"]]
):
Expand Down
29 changes: 28 additions & 1 deletion praw/models/reddit/mixins/inboxable.py
Expand Up @@ -72,7 +72,7 @@ def mark_read(self):
:meth:`~.mark_unread`
To mark the whole inbox as read with a single network request, use
:meth:`praw.models.Inbox.mark_read`
:meth:`praw.models.Inbox.mark_all_read`
"""
self._reddit.inbox.mark_read([self])
Expand Down Expand Up @@ -101,6 +101,33 @@ def mark_unread(self):
"""
self._reddit.inbox.mark_unread([self])

def unblock_subreddit(self):
"""Unblock a subreddit.
.. note::
This method pertains only to objects which were retrieved via the inbox.
For example, to unblock all blocked subreddits that you can find by going
through your inbox:
.. code-block:: python
from praw.models import SubredditMessage
subs = set()
for item in reddit.inbox.messages(limit=None):
if isinstance(item, SubredditMessage):
if (
item.subject == "[message from blocked subreddit]"
and str(item.subreddit) not in subs
):
item.unblock_subreddit()
subs.add(str(item.subreddit))
"""
self._reddit.post(API_PATH["unblock_subreddit"], data={"id": self.fullname})

def uncollapse(self):
"""Mark the item as uncollapsed.
Expand Down

0 comments on commit c5f1540

Please sign in to comment.