From 2ff419a5e7a56fe55763aebc0213c8ece0d2ada3 Mon Sep 17 00:00:00 2001 From: "Dmitry D. Chernov" Date: Thu, 11 May 2017 21:16:46 +1000 Subject: [PATCH] TelegramClient: Remove redundant check for adding update handlers Adding update handlers when not authorized makes no negative consequences. Also, check was implemented badly - update handlers can be added after logout/disconnect, for example. --- telethon/telegram_client.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 46b88887..0db78847 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -79,9 +79,6 @@ class TelegramClient: self.sender = None self.phone_code_hashes = {} - # We need to be signed in before we can listen for updates - self.signed_in = False - # endregion # region Connecting @@ -121,8 +118,6 @@ class TelegramClient: # although many other options are available! self.dc_options = result.dc_options - # We're signed in if we're authorized - self.signed_in = self.is_user_authorized() return True except RPCError as error: print('Could not stabilise initial connection: {}'.format(error)) @@ -241,9 +236,6 @@ class TelegramClient: self.session.user = result.user self.session.save() - # Now that we're authorized, set the signed_in flag - # to True so update handlers can be added - self.signed_in = True return True def sign_up(self, phone_number, code, first_name, last_name=''): @@ -728,9 +720,9 @@ class TelegramClient: def add_update_handler(self, handler): """Adds an update handler (a function which takes a TLObject, an update, as its parameter) and listens for updates""" - if not self.signed_in: - raise ValueError( - "You cannot add update handlers until you've signed in.") + if not self.sender: + raise RuntimeError( + "You should connect at least once to add update handlers.") self.sender.add_update_handler(handler)