Skip to content

Commit

Permalink
Merge pull request #249 from praw-dev/modmail_fix
Browse files Browse the repository at this point in the history
Fix modmail reply bug
  • Loading branch information
LilSpazJoekp authored Jul 11, 2023
2 parents 55f4fe8 + 47302e3 commit 794cde5
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 @@ -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
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 794cde5

Please sign in to comment.