Move graphql_to_poll -> Poll._from_graphql

This commit is contained in:
Mads Marquart
2019-03-07 19:52:29 +01:00
parent e51ce99c1a
commit 0578ea2c3c
4 changed files with 10 additions and 12 deletions

View File

@@ -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(

View File

@@ -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(

View File

@@ -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):

View File

@@ -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,