From 1f961b2ca7d031d8da9c8127870e5d0119ca2e4b Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 10 Mar 2019 19:39:22 +0100 Subject: [PATCH] Move thread parser dispatching into _client.py I know, it's not pretty, but it doesn't belong in _graphql.py either --- fbchat/_client.py | 15 ++++++++++++--- fbchat/_graphql.py | 13 ------------- fbchat/graphql.py | 1 - 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index 9ff9c47..12374b4 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -1158,9 +1158,18 @@ class Client(object): ) ) - return [ - graphql_to_thread(node) for node in j["viewer"]["message_threads"]["nodes"] - ] + rtn = [] + for node in j["viewer"]["message_threads"]["nodes"]: + _type = node.get("thread_type") + if _type == "GROUP": + rtn.append(Group._from_graphql(node)) + elif _type == "ONE_TO_ONE": + rtn.append(User._from_thread_fetch(node)) + else: + raise FBchatException( + "Unknown thread type: {}, with data: {}".format(_type, node) + ) + return rtn def fetchUnread(self): """ diff --git a/fbchat/_graphql.py b/fbchat/_graphql.py index 672558c..31d9931 100644 --- a/fbchat/_graphql.py +++ b/fbchat/_graphql.py @@ -82,19 +82,6 @@ def graphql_to_message(message): return rtn -def graphql_to_thread(thread): - if thread["thread_type"] == "GROUP": - return Group._from_graphql(thread) - elif thread["thread_type"] == "ONE_TO_ONE": - return User._from_thread_fetch(thread) - else: - raise FBchatException( - "Unknown thread type: {}, with data: {}".format( - thread.get("thread_type"), thread - ) - ) - - def graphql_queries_to_json(*queries): """ Queries should be a list of GraphQL objects diff --git a/fbchat/graphql.py b/fbchat/graphql.py index f0ea04f..4906656 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -9,7 +9,6 @@ from ._graphql import ( WHITESPACE, ConcatJSONDecoder, graphql_to_message, - graphql_to_thread, graphql_queries_to_json, graphql_response_to_json, GraphQL,