diff --git a/fbchat/_client.py b/fbchat/_client.py index cf1551a..2c246b1 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -2836,7 +2836,7 @@ class Client(object): thread_id, thread_type = getThreadIdAndThreadType(metadata) event_type = delta["untypedData"]["event_type"] poll_json = json.loads(delta["untypedData"]["question_json"]) - poll = graphql_to_poll(poll_json) + poll = Poll._from_graphql(poll_json) if event_type == "question_creation": # User created group poll self.onPollCreated( diff --git a/fbchat/_graphql.py b/fbchat/_graphql.py index 366a7ee..3e9e656 100644 --- a/fbchat/_graphql.py +++ b/fbchat/_graphql.py @@ -217,16 +217,6 @@ def graphql_to_live_location(a): ) -def graphql_to_poll(a): - rtn = Poll( - title=a.get("title") if a.get("title") else a.get("text"), - options=[PollOption._from_graphql(m) for m in a.get("options")], - ) - rtn.uid = int(a["id"]) - rtn.options_count = a.get("total_count") - return rtn - - def graphql_to_plan(a): if a.get("event_members"): rtn = Plan( diff --git a/fbchat/_poll.py b/fbchat/_poll.py index d99e57e..2b91122 100644 --- a/fbchat/_poll.py +++ b/fbchat/_poll.py @@ -17,6 +17,15 @@ class Poll(object): #: Options count options_count = attr.ib(None, init=False) + @classmethod + def _from_graphql(cls, data): + return cls( + uid=int(data["id"]), + title=data.get("title") if data.get("title") else data.get("text"), + options=[PollOption._from_graphql(m) for m in data.get("options")], + options_count=data.get("total_count"), + ) + @attr.s(cmp=False) class PollOption(object): diff --git a/fbchat/graphql.py b/fbchat/graphql.py index b1fee72..0d99a87 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -13,7 +13,6 @@ from ._graphql import ( graphql_to_extensible_attachment, graphql_to_subattachment, graphql_to_live_location, - graphql_to_poll, graphql_to_plan, graphql_to_quick_reply, graphql_to_message,