Refactor ChatColor

This commit is contained in:
KurimuzonAkuma 2023-12-06 11:07:26 +03:00
parent f85fdc838e
commit 7b199bde9c
3 changed files with 14 additions and 12 deletions

View File

@ -263,7 +263,7 @@ class Chat(Object):
restrictions=types.List([types.Restriction._parse(r) for r in user.restriction_reason]) or None,
dc_id=getattr(getattr(user, "photo", None), "dc_id", None),
reply_color=types.ChatColor._parse(getattr(user, "color", None)),
profile_color=types.ChatColor._parse(getattr(user, "profile_color", None), for_profile=True),
profile_color=types.ChatColor._parse_profile_color(getattr(user, "profile_color", None)),
client=client
)

View File

@ -44,19 +44,21 @@ class ChatColor(Object):
self.background_emoji_id = background_emoji_id
@staticmethod
def _parse(color: "raw.types.PeerColor" = None, for_profile: bool = None) -> Optional["ChatColor"]:
def _parse(color: "raw.types.PeerColor" = None) -> Optional["ChatColor"]:
if not color:
return None
chat_color = getattr(color, "color", None)
if not chat_color is None:
if for_profile:
chat_color = enums.ProfileColor(color.color)
else:
chat_color = enums.ReplyColor(color.color)
return ChatColor(
color=chat_color,
color=enums.ReplyColor(color.color) if getattr(color, "color", None) else None,
background_emoji_id=getattr(color, "background_emoji_id", None)
)
@staticmethod
def _parse_profile_color(color: "raw.types.PeerColor" = None) -> Optional["ChatColor"]:
if not color:
return None
return ChatColor(
color=enums.ProfileColor(color.color) if getattr(color, "color", None) else None,
background_emoji_id=getattr(color, "background_emoji_id", None)
)

View File

@ -281,7 +281,7 @@ class User(Object, Update):
photo=types.ChatPhoto._parse(client, user.photo, user.id, user.access_hash),
restrictions=types.List([types.Restriction._parse(r) for r in user.restriction_reason]) or None,
reply_color=types.ChatColor._parse(getattr(user, "color", None)),
profile_color=types.ChatColor._parse(getattr(user, "profile_color", None), for_profile=True),
profile_color=types.ChatColor._parse_profile_color(getattr(user, "profile_color", None)),
client=client
)