Skip to content

Commit

Permalink
Merge pull request #208 from praw-dev/modmail_obj_ids
Browse files Browse the repository at this point in the history
Don't set obj_ids since it can be missing data
  • Loading branch information
LilSpazJoekp committed Nov 28, 2022
2 parents 4b023ff + 35067ed commit 161fc05
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions asyncpraw/objector.py
Expand Up @@ -70,6 +70,7 @@ def _objectify_dict(self, data):
"conversations",
"conversation",
}.intersection(data):
# fetched conversation
data.update(
data.pop("conversation")
if "conversation" in data
Expand All @@ -81,12 +82,24 @@ def _objectify_dict(self, data):
"legacyFirstMessageId",
"state",
}.issubset(data):
# not fetched conversation i.e., from conversations()
del data["objIds"] # delete objIds since it could be missing data
parser = self.parsers["ModmailConversation"]
elif {"conversationIds", "conversations", "messages"}.issubset(data):
data["conversations"] = [
data["conversations"][conversation_id]
for conversation_id in data["conversationIds"]
]
# modmail conversations
conversations = []
for conversation_id in data["conversationIds"]:
conversation = data["conversations"][conversation_id]
# set if the numMessages is same as number of messages in objIds
if conversation["numMessages"] == len(
[obj for obj in conversation["objIds"] if obj["key"] == "messages"]
):
conversation["messages"] = [
self.objectify(data["messages"][obj_id["id"]])
for obj_id in conversation["objIds"]
]
conversations.append(conversation)
data["conversations"] = conversations
data = snake_case_keys(data)
parser = self.parsers["ModmailConversations-list"]
elif {"actionTypeId", "author", "date"}.issubset(data):
Expand Down

0 comments on commit 161fc05

Please sign in to comment.