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.
This commit is contained in:
Dmitry D. Chernov 2017-05-11 21:16:46 +10:00 committed by Lonami
parent b7ed6d9ec1
commit 2ff419a5e7

View File

@ -79,9 +79,6 @@ class TelegramClient:
self.sender = None self.sender = None
self.phone_code_hashes = {} self.phone_code_hashes = {}
# We need to be signed in before we can listen for updates
self.signed_in = False
# endregion # endregion
# region Connecting # region Connecting
@ -121,8 +118,6 @@ class TelegramClient:
# although many other options are available! # although many other options are available!
self.dc_options = result.dc_options self.dc_options = result.dc_options
# We're signed in if we're authorized
self.signed_in = self.is_user_authorized()
return True return True
except RPCError as error: except RPCError as error:
print('Could not stabilise initial connection: {}'.format(error)) print('Could not stabilise initial connection: {}'.format(error))
@ -241,9 +236,6 @@ class TelegramClient:
self.session.user = result.user self.session.user = result.user
self.session.save() 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 return True
def sign_up(self, phone_number, code, first_name, last_name=''): def sign_up(self, phone_number, code, first_name, last_name=''):
@ -728,9 +720,9 @@ class TelegramClient:
def add_update_handler(self, handler): def add_update_handler(self, handler):
"""Adds an update handler (a function which takes a TLObject, """Adds an update handler (a function which takes a TLObject,
an update, as its parameter) and listens for updates""" an update, as its parameter) and listens for updates"""
if not self.signed_in: if not self.sender:
raise ValueError( raise RuntimeError(
"You cannot add update handlers until you've signed in.") "You should connect at least once to add update handlers.")
self.sender.add_update_handler(handler) self.sender.add_update_handler(handler)