diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 15db2e73..c169f54f 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -129,29 +129,32 @@ def parse_chat_photo(photo): ) -def parse_last_seen(user: types.User) -> pyrogram_types.UserStatus: - if user.bot: +def parse_update_user_status(update: types.UpdateUserStatus) -> pyrogram_types.User: + return pyrogram_types.User(id=update.user_id, status=parse_user_status(update.status)) + + +def parse_user_status(user_status, is_bot: bool = False) -> pyrogram_types.UserStatus or None: + if is_bot: return None - status = user.status - last_seen = pyrogram_types.UserStatus() + status = pyrogram_types.UserStatus() - if isinstance(status, types.UserStatusOnline): - last_seen.online = True - last_seen.date = status.expires - elif isinstance(status, types.UserStatusOffline): - last_seen.offline = True - last_seen.date = status.was_online - elif isinstance(status, types.UserStatusRecently): - last_seen.recently = True - elif isinstance(status, types.UserStatusLastWeek): - last_seen.within_week = True - elif isinstance(status, types.UserStatusLastMonth): - last_seen.within_month = True + if isinstance(user_status, types.UserStatusOnline): + status.online = True + status.date = user_status.expires + elif isinstance(user_status, types.UserStatusOffline): + status.offline = True + status.date = user_status.was_online + elif isinstance(user_status, types.UserStatusRecently): + status.recently = True + elif isinstance(user_status, types.UserStatusLastWeek): + status.within_week = True + elif isinstance(user_status, types.UserStatusLastMonth): + status.within_month = True else: - last_seen.long_time_ago = True + status.long_time_ago = True - return last_seen + return status def parse_user(user: types.User) -> pyrogram_types.User or None: @@ -168,7 +171,7 @@ def parse_user(user: types.User) -> pyrogram_types.User or None: language_code=user.lang_code, phone_number=user.phone, photo=parse_chat_photo(user.photo), - last_seen=parse_last_seen(user), + status=parse_user_status(user.status, user.bot), ) if user else None