mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-20 13:31:00 +03:00
Fix connection parameters not being copied on reconnection (#129)
This commit is contained in:
parent
be33ae4e80
commit
765ae870cf
|
@ -181,7 +181,10 @@ class TelegramClient(TelegramBareClient):
|
||||||
|
|
||||||
# Create a temporary session for this IP address, which needs
|
# Create a temporary session for this IP address, which needs
|
||||||
# to be different because each auth_key is unique per DC.
|
# to be different because each auth_key is unique per DC.
|
||||||
session = JsonSession(None)
|
#
|
||||||
|
# Construct this session with the connection parameters
|
||||||
|
# (system version, device model...) from the current one.
|
||||||
|
session = JsonSession(self.session)
|
||||||
session.server_address = dc.ip_address
|
session.server_address = dc.ip_address
|
||||||
session.port = dc.port
|
session.port = dc.port
|
||||||
client = TelegramBareClient(session, self.api_id, self.api_hash)
|
client = TelegramBareClient(session, self.api_id, self.api_hash)
|
||||||
|
|
|
@ -99,14 +99,28 @@ class JsonSession:
|
||||||
through an official Telegram client to revoke the authorization.
|
through an official Telegram client to revoke the authorization.
|
||||||
"""
|
"""
|
||||||
def __init__(self, session_user_id):
|
def __init__(self, session_user_id):
|
||||||
|
"""session_user_id should either be a string or another Session.
|
||||||
|
Note that if another session is given, only parameters like
|
||||||
|
those required to init a connection will be copied.
|
||||||
|
"""
|
||||||
# These values will NOT be saved
|
# These values will NOT be saved
|
||||||
self.session_user_id = session_user_id
|
if isinstance(session_user_id, str):
|
||||||
|
self.session_user_id = session_user_id
|
||||||
|
|
||||||
# For connection purposes
|
# For connection purposes
|
||||||
self.device_model = platform.node()
|
self.device_model = platform.node()
|
||||||
self.system_version = platform.system()
|
self.system_version = platform.system()
|
||||||
self.app_version = '0'
|
self.app_version = '0'
|
||||||
self.lang_code = 'en'
|
self.lang_code = 'en'
|
||||||
|
|
||||||
|
elif isinstance(session_user_id, JsonSession):
|
||||||
|
self.session_user_id = None
|
||||||
|
|
||||||
|
session = session_user_id
|
||||||
|
self.device_model = session.device_model
|
||||||
|
self.system_version = session.system_version
|
||||||
|
self.app_version = session.app_version
|
||||||
|
self.lang_code = session.lang_code
|
||||||
|
|
||||||
# Cross-thread safety
|
# Cross-thread safety
|
||||||
self._lock = Lock()
|
self._lock = Lock()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user