From bf3609ec0a7b34342e48cbaaa97b4078798126ab Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 15 Dec 2018 17:29:51 +0100 Subject: [PATCH] Refactor User --- pyrogram/client/types/user_and_chats/user.py | 54 +++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py index 06045b00..e460522b 100644 --- a/pyrogram/client/types/user_and_chats/user.py +++ b/pyrogram/client/types/user_and_chats/user.py @@ -16,7 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from pyrogram.api import types from pyrogram.api.core import Object +from .user_status import UserStatus +from .chat_photo import ChatPhoto class User(Object): @@ -68,23 +71,11 @@ class User(Object): ID = 0xb0700001 - def __init__( - self, - id: int, - is_self: bool, - is_contact: bool, - is_mutual_contact: bool, - is_deleted: bool, - is_bot: bool, - first_name: str, - status=None, - last_name: str = None, - username: str = None, - language_code: str = None, - phone_number: str = None, - photo=None, - restriction_reason: str = None - ): + def __init__(self, id: int, is_self: bool, is_contact: bool, is_mutual_contact: bool, is_deleted: bool, + is_bot: bool, first_name: str, *, + last_name: str = None, status=None, username: str = None, language_code: str = None, + phone_number: str = None, photo=None, restriction_reason: str = None, + client=None, raw=None): self.id = id self.is_self = is_self self.is_contact = is_contact @@ -92,10 +83,37 @@ class User(Object): self.is_deleted = is_deleted self.is_bot = is_bot self.first_name = first_name - self.status = status + self.last_name = last_name + self.status = status self.username = username self.language_code = language_code self.phone_number = phone_number self.photo = photo self.restriction_reason = restriction_reason + + self._client = client + self._raw = raw + + @staticmethod + def parse(client, user: types.User) -> "User" or None: + if user is None: + return None + + return User( + id=user.id, + is_self=user.is_self, + is_contact=user.contact, + is_mutual_contact=user.mutual_contact, + is_deleted=user.deleted, + is_bot=user.bot, + first_name=user.first_name, + last_name=user.last_name, + status=UserStatus.parse(client, user), + username=user.username, + language_code=user.lang_code, + phone_number=user.phone, + photo=ChatPhoto.parse(client, user.photo), + restriction_reason=user.restriction_reason, + client=client, raw=user + )