Pyrofork: Move Non-fragment username from {chat,user}.usernames to {chat,user}.username

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2023-10-23 20:11:53 +07:00
parent 207d0929d8
commit e4964e8470
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
2 changed files with 12 additions and 4 deletions

View file

@ -268,12 +268,16 @@ class Chat(Object):
def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
peer_id = utils.get_channel_id(channel.id)
restriction_reason = getattr(channel, "restriction_reason", [])
user_name = getattr(channel, "username", None)
active_usernames = getattr(channel, "usernames", [])
usernames = None
if len(active_usernames) >= 1:
usernames = []
for username in active_usernames:
usernames.append(types.Username._parse(username))
if username.editable:
user_name = username.username
else:
usernames.append(types.Username._parse(username))
return Chat(
id=peer_id,
@ -285,7 +289,7 @@ class Chat(Object):
is_fake=getattr(channel, "fake", None),
is_forum=getattr(channel, "forum", None),
title=channel.title,
username=getattr(channel, "username", None),
username=user_name,
usernames=usernames,
photo=types.ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id,
getattr(channel, "access_hash", 0)),

View file

@ -229,12 +229,16 @@ class User(Object, Update):
def _parse(client, user: "raw.base.User") -> Optional["User"]:
if user is None or isinstance(user, raw.types.UserEmpty):
return None
user_name = user.username
active_usernames = getattr(user, "usernames", [])
usernames = None
if len(active_usernames) >= 1:
usernames = []
for username in active_usernames:
usernames.append(types.Username._parse(username))
if username.editable:
user_name = username.username
else:
usernames.append(types.Username._parse(username))
return User(
id=user.id,
@ -252,7 +256,7 @@ class User(Object, Update):
first_name=user.first_name,
last_name=user.last_name,
**User._parse_status(user.status, user.bot),
username=user.username,
username=user_name,
usernames=usernames,
language_code=user.lang_code,
emoji_status=types.EmojiStatus._parse(client, user.emoji_status),