Be more explicit in UserData/PageData parsing

Allows us to make some fields required (aka. not None)
This commit is contained in:
Mads Marquart
2020-01-09 14:51:27 +01:00
parent 2459a0251a
commit e039e88f80
3 changed files with 40 additions and 37 deletions

View File

@@ -501,7 +501,7 @@ class Client:
if pages_and_users.get(_id) is None:
raise FBchatException("Could not fetch thread {}".format(_id))
entry.update(pages_and_users[_id])
if "first_name" in entry["type"]:
if "first_name" in entry:
rtn[_id] = UserData._from_graphql(self.session, entry)
else:
rtn[_id] = PageData._from_graphql(self.session, entry)
@@ -551,7 +551,9 @@ class Client:
if _type == "GROUP":
rtn.append(GroupData._from_graphql(self.session, node))
elif _type == "ONE_TO_ONE":
rtn.append(UserData._from_thread_fetch(self.session, node))
user = UserData._from_thread_fetch(self.session, node)
if user:
rtn.append(user)
else:
raise FBchatException(
"Unknown thread type: {}, with data: {}".format(_type, node)