Improved default session infos

Removes rendundant system-type declaration, as it should be specified already when creating an API
Adopts same form of TgDesktop
This could be harmful if someone already has a session with previous data, as telegram could revoke the session
In this case should be adviced using `device_model=platform.uname().system,system_version=platform.uname().release` as arguments
This commit is contained in:
Tanya 2020-09-06 16:58:45 +02:00 committed by Tanya
parent 02b8f1d007
commit 17182fbc83

View File

@ -161,11 +161,11 @@ class TelegramBaseClient(abc.ABC):
device_model (`str`, optional):
"Device model" to be sent when creating the initial connection.
Defaults to ``platform.node()``.
Defaults to 'PC (n)bit' derived from ``platform.uname().machine``, or his direct value if unknown.
system_version (`str`, optional):
"System version" to be sent when creating the initial connection.
Defaults to ``platform.system()``.
Defaults to ``platform.uname().release`` stripped of everything ahead of -.
app_version (`str`, optional):
"App version" to be sent when creating the initial connection.
@ -320,11 +320,20 @@ class TelegramBaseClient(abc.ABC):
# Used on connection. Capture the variables in a lambda since
# exporting clients need to create this InvokeWithLayerRequest.
system = platform.uname()
if system.machine in ['x86_64','AMD64']:
default_device_model = 'PC 64bit'
elif system.machine in ['i386','i686','x86']:
default_device_model = 'PC 32bit'
else:
default_device_model = system.machine
get_system_version = lambda x : x[:x.index('-')] if '-' in x else x
default_system_version = get_system_version(system.release)
self._init_with = lambda x: functions.InvokeWithLayerRequest(
LAYER, functions.InitConnectionRequest(
api_id=self.api_id,
device_model=device_model or system.system or 'Unknown',
system_version=system_version or system.release or '1.0',
device_model=device_model or default_device_model or 'Unknown',
system_version=system_version or default_system_version or '1.0',
app_version=app_version or self.__version__,
lang_code=lang_code,
system_lang_code=system_lang_code,