Move graphql_to_user -> User._from_graphql
This commit is contained in:
@@ -730,7 +730,7 @@ class Client(object):
|
||||
GraphQL(query=GraphQL.SEARCH_USER, params={"search": name, "limit": limit})
|
||||
)
|
||||
|
||||
return [graphql_to_user(node) for node in j[name]["users"]["nodes"]]
|
||||
return [User._from_graphql(node) for node in j[name]["users"]["nodes"]]
|
||||
|
||||
def searchForPages(self, name, limit=10):
|
||||
"""
|
||||
@@ -785,7 +785,7 @@ class Client(object):
|
||||
rtn = []
|
||||
for node in j[name]["threads"]["nodes"]:
|
||||
if node["__typename"] == "User":
|
||||
rtn.append(graphql_to_user(node))
|
||||
rtn.append(User._from_graphql(node))
|
||||
elif node["__typename"] == "MessageThread":
|
||||
# MessageThread => Group thread
|
||||
rtn.append(graphql_to_group(node))
|
||||
@@ -1056,7 +1056,7 @@ class Client(object):
|
||||
raise FBchatException("Could not fetch thread {}".format(_id))
|
||||
entry.update(pages_and_users[_id])
|
||||
if entry["type"] == ThreadType.USER:
|
||||
rtn[_id] = graphql_to_user(entry)
|
||||
rtn[_id] = User._from_graphql(entry)
|
||||
else:
|
||||
rtn[_id] = graphql_to_page(entry)
|
||||
else:
|
||||
|
@@ -146,33 +146,6 @@ def graphql_to_message(message):
|
||||
return rtn
|
||||
|
||||
|
||||
def graphql_to_user(user):
|
||||
if user.get("profile_picture") is None:
|
||||
user["profile_picture"] = {}
|
||||
c_info = User._parse_customization_info(user)
|
||||
plan = None
|
||||
if user.get("event_reminders") and user["event_reminders"].get("nodes"):
|
||||
plan = Plan._from_graphql(user["event_reminders"]["nodes"][0])
|
||||
|
||||
return User(
|
||||
user["id"],
|
||||
url=user.get("url"),
|
||||
first_name=user.get("first_name"),
|
||||
last_name=user.get("last_name"),
|
||||
is_friend=user.get("is_viewer_friend"),
|
||||
gender=GENDERS.get(user.get("gender")),
|
||||
affinity=user.get("affinity"),
|
||||
nickname=c_info.get("nickname"),
|
||||
color=c_info.get("color"),
|
||||
emoji=c_info.get("emoji"),
|
||||
own_nickname=c_info.get("own_nickname"),
|
||||
photo=user["profile_picture"].get("uri"),
|
||||
name=user.get("name"),
|
||||
message_count=user.get("messages_count"),
|
||||
plan=plan,
|
||||
)
|
||||
|
||||
|
||||
def graphql_to_thread(thread):
|
||||
if thread["thread_type"] == "GROUP":
|
||||
return graphql_to_group(thread)
|
||||
|
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import attr
|
||||
from ._core import Enum
|
||||
from . import _util, _plan
|
||||
from ._thread import ThreadType, Thread
|
||||
|
||||
|
||||
@@ -65,6 +66,33 @@ class User(Thread):
|
||||
self.color = color
|
||||
self.emoji = emoji
|
||||
|
||||
@classmethod
|
||||
def _from_graphql(cls, data):
|
||||
if data.get("profile_picture") is None:
|
||||
data["profile_picture"] = {}
|
||||
c_info = cls._parse_customization_info(data)
|
||||
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["id"],
|
||||
url=data.get("url"),
|
||||
first_name=data.get("first_name"),
|
||||
last_name=data.get("last_name"),
|
||||
is_friend=data.get("is_viewer_friend"),
|
||||
gender=_util.GENDERS.get(data.get("gender")),
|
||||
affinity=data.get("affinity"),
|
||||
nickname=c_info.get("nickname"),
|
||||
color=c_info.get("color"),
|
||||
emoji=c_info.get("emoji"),
|
||||
own_nickname=c_info.get("own_nickname"),
|
||||
photo=data["profile_picture"].get("uri"),
|
||||
name=data.get("name"),
|
||||
message_count=data.get("messages_count"),
|
||||
plan=plan,
|
||||
)
|
||||
|
||||
|
||||
@attr.s(cmp=False)
|
||||
class ActiveStatus(object):
|
||||
|
@@ -13,7 +13,6 @@ from ._graphql import (
|
||||
graphql_to_subattachment,
|
||||
graphql_to_quick_reply,
|
||||
graphql_to_message,
|
||||
graphql_to_user,
|
||||
graphql_to_thread,
|
||||
graphql_to_group,
|
||||
graphql_to_page,
|
||||
|
Reference in New Issue
Block a user