From 6a0a271d24ee4efb7b64281c13603a83e2322004 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 17 Dec 2018 16:28:16 +0100 Subject: [PATCH] Fix broken UpdateStatus in case of incoming updates --- pyrogram/client/types/user_and_chats/user.py | 2 +- .../types/user_and_chats/user_status.py | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py index 1c1d41fe..ed3ea16d 100644 --- a/pyrogram/client/types/user_and_chats/user.py +++ b/pyrogram/client/types/user_and_chats/user.py @@ -104,7 +104,7 @@ class User(PyrogramType): is_bot=user.bot, first_name=user.first_name, last_name=user.last_name, - status=UserStatus.parse(client, user), + status=UserStatus.parse(client, user.status, user.id, user.bot), username=user.username, language_code=user.lang_code, phone_number=user.phone, diff --git a/pyrogram/client/types/user_and_chats/user_status.py b/pyrogram/client/types/user_and_chats/user_status.py index d6bfa13d..d9e27498 100644 --- a/pyrogram/client/types/user_and_chats/user_status.py +++ b/pyrogram/client/types/user_and_chats/user_status.py @@ -77,24 +77,23 @@ class UserStatus(PyrogramType): self.long_time_ago = long_time_ago @staticmethod - def parse(client, user: types.User): - if user.bot: + def parse(client, user_status, user_id: int, is_bot: bool = False): + if is_bot: return None - raw_status = user.status - status = UserStatus(user_id=user.id, client=client, raw=raw_status) + status = UserStatus(user_id=user_id, client=client, raw=user_status) - if isinstance(raw_status, types.UserStatusOnline): + if isinstance(user_status, types.UserStatusOnline): status.online = True - status.date = raw_status.expires - elif isinstance(raw_status, types.UserStatusOffline): + status.date = user_status.expires + elif isinstance(user_status, types.UserStatusOffline): status.offline = True - status.date = raw_status.was_online - elif isinstance(raw_status, types.UserStatusRecently): + status.date = user_status.was_online + elif isinstance(user_status, types.UserStatusRecently): status.recently = True - elif isinstance(raw_status, types.UserStatusLastWeek): + elif isinstance(user_status, types.UserStatusLastWeek): status.within_week = True - elif isinstance(raw_status, types.UserStatusLastMonth): + elif isinstance(user_status, types.UserStatusLastMonth): status.within_month = True else: status.long_time_ago = True