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 55f4fe8 commit 47302e3
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,10 @@ Unreleased

- Drop asyncio_extras dependency, use contextlib.asynccontextmanager instead.

**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
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

0 comments on commit 47302e3

Please sign in to comment.