From 279f637c7564ccdce299be9e9a9b58d7292019df Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 7 Mar 2019 18:54:38 +0100 Subject: [PATCH] Move graphql_color_to_enum -> ThreadColor._from_graphql --- fbchat/_client.py | 2 +- fbchat/_graphql.py | 12 +----------- fbchat/_thread.py | 10 ++++++++++ fbchat/graphql.py | 1 - 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index 607dd58..f5f30be 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -2577,7 +2577,7 @@ class Client(object): # Color change elif delta_type == "change_thread_theme": - new_color = graphql_color_to_enum(delta["untypedData"]["theme_color"]) + new_color = ThreadColor._from_graphql(delta["untypedData"]["theme_color"]) thread_id, thread_type = getThreadIdAndThreadType(metadata) self.onColorChange( mid=mid, diff --git a/fbchat/_graphql.py b/fbchat/_graphql.py index 7e83500..160993c 100644 --- a/fbchat/_graphql.py +++ b/fbchat/_graphql.py @@ -27,16 +27,6 @@ class ConcatJSONDecoder(json.JSONDecoder): # End shameless copy -def graphql_color_to_enum(color): - if color is None: - return None - if not color: - return ThreadColor.MESSENGER_BLUE - color = color[2:] # Strip the alpha value - color_value = "#{}".format(color.lower()) - return ThreadColor._extend_if_invalid(color_value) - - def get_customization_info(thread): if thread is None or thread.get("customization_info") is None: return {} @@ -44,7 +34,7 @@ def get_customization_info(thread): rtn = { "emoji": info.get("emoji"), - "color": graphql_color_to_enum(info.get("outgoing_bubble_color")), + "color": ThreadColor._from_graphql(info.get("outgoing_bubble_color")), } if ( thread.get("thread_type") == "GROUP" diff --git a/fbchat/_thread.py b/fbchat/_thread.py index 6b4641e..d4a8391 100644 --- a/fbchat/_thread.py +++ b/fbchat/_thread.py @@ -42,6 +42,16 @@ class ThreadColor(Enum): BRILLIANT_ROSE = "#ff5ca1" BILOBA_FLOWER = "#a695c7" + @classmethod + def _from_graphql(cls, color): + if color is None: + return None + if not color: + return cls.MESSENGER_BLUE + color = color[2:] # Strip the alpha value + value = "#{}".format(color.lower()) + return cls._extend_if_invalid(value) + @attr.s(cmp=False, init=False) class Thread(object): diff --git a/fbchat/graphql.py b/fbchat/graphql.py index aeef27c..00f46e4 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -8,7 +8,6 @@ from ._graphql import ( FLAGS, WHITESPACE, ConcatJSONDecoder, - graphql_color_to_enum, get_customization_info, graphql_to_sticker, graphql_to_attachment,