mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Refactor ChatColor
This commit is contained in:
parent
f85fdc838e
commit
7b199bde9c
@ -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
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user