From 2b090f888839834e931bd736ec7f994752d70cb8 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 26 Jun 2018 16:20:30 +0200 Subject: [PATCH] Fix connect not saving different authkeys --- telethon/client/telegrambaseclient.py | 4 ++-- telethon/crypto/authkey.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index a7aec132..099324a8 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -271,7 +271,7 @@ class TelegramBaseClient(abc.ABC): """ Connects to Telegram. """ - had_auth = self.session.auth_key is not None + old_auth = self.session.auth_key await self._sender.connect( self.session.server_address, self.session.port) @@ -280,7 +280,7 @@ class TelegramBaseClient(abc.ABC): self._updates_handle = self._loop.create_task(self._update_loop()) - if not had_auth: + if old_auth != self._sender.state.auth_key: self.session.auth_key = self._sender.state.auth_key self.session.save() diff --git a/telethon/crypto/authkey.py b/telethon/crypto/authkey.py index 31d1fc9c..64f65407 100644 --- a/telethon/crypto/authkey.py +++ b/telethon/crypto/authkey.py @@ -38,3 +38,6 @@ class AuthKey: # Calculates the message key from the given data return int.from_bytes(sha1(data).digest()[4:20], 'little', signed=True) + + def __eq__(self, other): + return isinstance(other, type(self)) and other.key == self.key