Skip to content

Commit

Permalink
Fix modmail reply bug
Browse files Browse the repository at this point in the history
(cherry picked from commit praw-dev/praw@5984516)
  • Loading branch information
LilSpazJoekp committed Jul 11, 2023
1 parent 4f4b0b4 commit 5aa7f8b
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Async PRAW follows `semantic versioning <https://semver.org/>`_.
Unreleased
----------

**Fixed**

- An issue with replying to a modmail conversation results in a error.

7.7.0 (2023/02/25)
------------------

Expand Down
12 changes: 9 additions & 3 deletions asyncpraw/models/reddit/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,15 @@ async def reply(
response = await self._reddit.post(
API_PATH["modmail_conversation"].format(id=self.id), data=data
)
message_id = response["conversation"]["objIds"][-1]["id"]
message_data = response["messages"][message_id]
return self._reddit._objector.objectify(message_data)
if isinstance(response, dict):
# Reddit recently changed the response format, so we need to handle both in case they change it back
message_id = response["conversation"]["objIds"][-1]["id"]
message_data = response["messages"][message_id]
return self._reddit._objector.objectify(message_data)
else:
for message in response.messages:
if message.id == response.obj_ids[-1]["id"]:
return message

async def unarchive(self):
"""Unarchive the conversation.
Expand Down
Loading

0 comments on commit 5aa7f8b

Please sign in to comment.