Move graphql_to_group -> Group._from_graphql
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import attr
|
||||
from . import _plan
|
||||
from ._thread import ThreadType, Thread
|
||||
|
||||
|
||||
@@ -60,6 +61,49 @@ class Group(Thread):
|
||||
self.approval_requests = approval_requests
|
||||
self.join_link = join_link
|
||||
|
||||
@classmethod
|
||||
def _from_graphql(cls, data):
|
||||
if data.get("image") is None:
|
||||
data["image"] = {}
|
||||
c_info = cls._parse_customization_info(data)
|
||||
last_message_timestamp = None
|
||||
if "last_message" in data:
|
||||
last_message_timestamp = data["last_message"]["nodes"][0][
|
||||
"timestamp_precise"
|
||||
]
|
||||
plan = None
|
||||
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
||||
plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0])
|
||||
|
||||
return cls(
|
||||
data["thread_key"]["thread_fbid"],
|
||||
participants=set(
|
||||
[
|
||||
node["messaging_actor"]["id"]
|
||||
for node in data["all_participants"]["nodes"]
|
||||
]
|
||||
),
|
||||
nicknames=c_info.get("nicknames"),
|
||||
color=c_info.get("color"),
|
||||
emoji=c_info.get("emoji"),
|
||||
admins=set([node.get("id") for node in data.get("thread_admins")]),
|
||||
approval_mode=bool(data.get("approval_mode"))
|
||||
if data.get("approval_mode") is not None
|
||||
else None,
|
||||
approval_requests=set(
|
||||
node["requester"]["id"]
|
||||
for node in data["group_approval_queue"]["nodes"]
|
||||
)
|
||||
if data.get("group_approval_queue")
|
||||
else None,
|
||||
join_link=data["joinable_mode"].get("link"),
|
||||
photo=data["image"].get("uri"),
|
||||
name=data.get("name"),
|
||||
message_count=data.get("messages_count"),
|
||||
last_message_timestamp=last_message_timestamp,
|
||||
plan=plan,
|
||||
)
|
||||
|
||||
|
||||
@attr.s(cmp=False, init=False)
|
||||
class Room(Group):
|
||||
|
Reference in New Issue
Block a user