Move graphql_color_to_enum -> ThreadColor._from_graphql

This commit is contained in:
Mads Marquart
2019-03-07 18:54:38 +01:00
parent d940b64517
commit 279f637c75
4 changed files with 12 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,6 @@ from ._graphql import (
FLAGS,
WHITESPACE,
ConcatJSONDecoder,
graphql_color_to_enum,
get_customization_info,
graphql_to_sticker,
graphql_to_attachment,