mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Let only the LogOut request be confirmed via ack
This commit is contained in:
parent
3e611cdd42
commit
6d1ce4d48d
|
@ -12,7 +12,7 @@ cols, rows = shutil.get_terminal_size()
|
||||||
def print_title(title):
|
def print_title(title):
|
||||||
# Clear previous window
|
# Clear previous window
|
||||||
print('\n')
|
print('\n')
|
||||||
available_cols = cols - 2 # -2 sincewe omit '┌' and '┐'
|
available_cols = cols - 2 # -2 since we omit '┌' and '┐'
|
||||||
print('┌{}┐'.format('─' * available_cols))
|
print('┌{}┐'.format('─' * available_cols))
|
||||||
print('│{}│'.format(title.center(available_cols)))
|
print('│{}│'.format(title.center(available_cols)))
|
||||||
print('└{}┘'.format('─' * available_cols))
|
print('└{}┘'.format('─' * available_cols))
|
||||||
|
|
|
@ -228,11 +228,15 @@ class MtProtoSender:
|
||||||
return self.handle_bad_msg_notification(msg_id, sequence, reader)
|
return self.handle_bad_msg_notification(msg_id, sequence, reader)
|
||||||
|
|
||||||
# msgs_ack, it may handle the request we wanted
|
# msgs_ack, it may handle the request we wanted
|
||||||
if self.ack_requests_confirm and code == 0x62d6b459:
|
if code == 0x62d6b459:
|
||||||
ack = reader.tgread_object()
|
ack = reader.tgread_object()
|
||||||
if request and request.msg_id in ack.msg_ids:
|
if request and request.msg_id in ack.msg_ids:
|
||||||
Log.w('Message ack confirmed a request')
|
Log.w('Ack found for the current request ID')
|
||||||
request.confirm_received = True
|
|
||||||
|
if self.ack_requests_confirm:
|
||||||
|
Log.w('Message ack confirmed a request')
|
||||||
|
request.confirm_received = True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If the code is not parsed manually, then it was parsed by the code generator!
|
# If the code is not parsed manually, then it was parsed by the code generator!
|
||||||
|
|
|
@ -121,9 +121,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 can now enable these (for such methods such as logout)
|
|
||||||
self.sender.ack_requests_confirm = True
|
|
||||||
|
|
||||||
# We're signed in if we're authorized
|
# We're signed in if we're authorized
|
||||||
self.signed_in = self.is_user_authorized()
|
self.signed_in = self.is_user_authorized()
|
||||||
return True
|
return True
|
||||||
|
@ -259,6 +256,9 @@ class TelegramClient:
|
||||||
|
|
||||||
def log_out(self):
|
def log_out(self):
|
||||||
"""Logs out and deletes the current session. Returns True if everything went OK"""
|
"""Logs out and deletes the current session. Returns True if everything went OK"""
|
||||||
|
# Only the logout request is confirmed via an ack request
|
||||||
|
# TODO This is only a supposition, there has to be a better way to handle acks
|
||||||
|
self.sender.ack_requests_confirm = True
|
||||||
try:
|
try:
|
||||||
self.invoke(LogOutRequest())
|
self.invoke(LogOutRequest())
|
||||||
if not self.session.delete():
|
if not self.session.delete():
|
||||||
|
@ -266,6 +266,8 @@ class TelegramClient:
|
||||||
|
|
||||||
self.session = None
|
self.session = None
|
||||||
except:
|
except:
|
||||||
|
# Something happened when logging out, restore the state back
|
||||||
|
self.sender.ack_requests_confirm = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user