mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
Avoid listening for updates if no update handlers are added
This only caused issues if it was the first time we logged in. All the cases are now covered
This commit is contained in:
parent
e035939aa2
commit
30f15e67ac
|
@ -54,6 +54,9 @@ 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
|
||||||
|
@ -88,6 +91,9 @@ class TelegramClient:
|
||||||
|
|
||||||
# We can now enable these (for such methods such as logout)
|
# We can now enable these (for such methods such as logout)
|
||||||
self.sender.ack_requests_confirm = True
|
self.sender.ack_requests_confirm = True
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
@ -167,8 +173,9 @@ class TelegramClient:
|
||||||
self.session.user = result.user
|
self.session.user = result.user
|
||||||
self.session.save()
|
self.session.save()
|
||||||
|
|
||||||
# Now that we're authorized, we can listen for incoming updates
|
# Now that we're authorized, set the signed_in flag
|
||||||
self.sender.set_listen_for_updates(True)
|
# 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=''):
|
||||||
|
@ -588,6 +595,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:
|
||||||
|
raise ValueError("You cannot add update handlers until you've signed in.")
|
||||||
|
|
||||||
self.sender.add_update_handler(handler)
|
self.sender.add_update_handler(handler)
|
||||||
|
|
||||||
def remove_update_handler(self, handler):
|
def remove_update_handler(self, handler):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user