Inline tdlibParameters in setTdlibParameters.

This commit is contained in:
levlam 2022-09-07 22:19:08 +03:00
parent ebb6770935
commit f6a2ecdded
13 changed files with 131 additions and 139 deletions

View File

@ -290,18 +290,17 @@ class TdExample {
create_authentication_query_handler());
},
[this](td_api::authorizationStateWaitTdlibParameters &) {
auto parameters = td_api::make_object<td_api::tdlibParameters>();
parameters->database_directory_ = "tdlib";
parameters->use_message_database_ = true;
parameters->use_secret_chats_ = true;
parameters->api_id_ = 94575;
parameters->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->application_version_ = "1.0";
parameters->enable_storage_optimizer_ = true;
send_query(td_api::make_object<td_api::setTdlibParameters>(std::move(parameters)),
create_authentication_query_handler());
auto request = td_api::make_object<td_api::setTdlibParameters>();
request->database_directory_ = "tdlib";
request->use_message_database_ = true;
request->use_secret_chats_ = true;
request->api_id_ = 94575;
request->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
request->system_language_code_ = "en";
request->device_model_ = "Desktop";
request->application_version_ = "1.0";
request->enable_storage_optimizer_ = true;
send_query(std::move(request), create_authentication_query_handler());
}));
}

View File

@ -67,18 +67,18 @@ namespace TdExample
}
if (_authorizationState is TdApi.AuthorizationStateWaitTdlibParameters)
{
TdApi.TdlibParameters parameters = new TdApi.TdlibParameters();
parameters.DatabaseDirectory = "tdlib";
parameters.UseMessageDatabase = true;
parameters.UseSecretChats = true;
parameters.ApiId = 94575;
parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters.SystemLanguageCode = "en";
parameters.DeviceModel = "Desktop";
parameters.ApplicationVersion = "1.0";
parameters.EnableStorageOptimizer = true;
TdApi.SetTdlibParameters request = new TdApi.SetTdlibParameters();
request.DatabaseDirectory = "tdlib";
request.UseMessageDatabase = true;
request.UseSecretChats = true;
request.ApiId = 94575;
request.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
request.SystemLanguageCode = "en";
request.DeviceModel = "Desktop";
request.ApplicationVersion = "1.0";
request.EnableStorageOptimizer = true;
_client.Send(new TdApi.SetTdlibParameters(parameters), new AuthorizationRequestHandler());
_client.Send(request, new AuthorizationRequestHandler());
}
else if (_authorizationState is TdApi.AuthorizationStateWaitPhoneNumber)
{

View File

@ -101,18 +101,18 @@ public final class Example {
}
switch (Example.authorizationState.getConstructor()) {
case TdApi.AuthorizationStateWaitTdlibParameters.CONSTRUCTOR:
TdApi.TdlibParameters parameters = new TdApi.TdlibParameters();
parameters.databaseDirectory = "tdlib";
parameters.useMessageDatabase = true;
parameters.useSecretChats = true;
parameters.apiId = 94575;
parameters.apiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters.systemLanguageCode = "en";
parameters.deviceModel = "Desktop";
parameters.applicationVersion = "1.0";
parameters.enableStorageOptimizer = true;
TdApi.SetTdlibParameters request = new TdApi.SetTdlibParameters();
request.databaseDirectory = "tdlib";
request.useMessageDatabase = true;
request.useSecretChats = true;
request.apiId = 94575;
request.apiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
request.systemLanguageCode = "en";
request.deviceModel = "Desktop";
request.applicationVersion = "1.0";
request.enableStorageOptimizer = true;
client.send(new TdApi.SetTdlibParameters(parameters), new AuthorizationRequestHandler());
client.send(parameters, new AuthorizationRequestHandler());
break;
case TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR: {
String phoneNumber = promptString("Please enter phone number: ");

View File

@ -94,16 +94,16 @@ while True:
# you MUST obtain your own api_id and api_hash at https://my.telegram.org
# and use them in the setTdlibParameters call
if auth_state['@type'] == 'authorizationStateWaitTdlibParameters':
td_send({'@type': 'setTdlibParameters', 'parameters': {
'database_directory': 'tdlib',
'use_message_database': True,
'use_secret_chats': True,
'api_id': 94575,
'api_hash': 'a3406de8d171bb422bb6ddf3bbd800e2',
'system_language_code': 'en',
'device_model': 'Desktop',
'application_version': '1.0',
'enable_storage_optimizer': True}})
td_send({'@type': 'setTdlibParameters',
'database_directory': 'tdlib',
'use_message_database': True,
'use_secret_chats': True,
'api_id': 94575,
'api_hash': 'a3406de8d171bb422bb6ddf3bbd800e2',
'system_language_code': 'en',
'device_model': 'Desktop',
'application_version': '1.0',
'enable_storage_optimizer': True})
# enter phone number to log in
if auth_state['@type'] == 'authorizationStateWaitPhoneNumber':

View File

@ -107,17 +107,15 @@ func updateAuthorizationState(authorizationState: Dictionary<String, Any>) {
case "authorizationStateWaitTdlibParameters":
client.queryAsync(query:[
"@type":"setTdlibParameters",
"parameters":[
"database_directory":"tdlib",
"use_message_database":true,
"use_secret_chats":true,
"api_id":94575,
"api_hash":"a3406de8d171bb422bb6ddf3bbd800e2",
"system_language_code":"en",
"device_model":"Desktop",
"application_version":"1.0",
"enable_storage_optimizer":true
]
"database_directory":"tdlib",
"use_message_database":true,
"use_secret_chats":true,
"api_id":94575,
"api_hash":"a3406de8d171bb422bb6ddf3bbd800e2",
"system_language_code":"en",
"device_model":"Desktop",
"application_version":"1.0",
"enable_storage_optimizer":true
]);
case "authorizationStateWaitPhoneNumber":

View File

@ -36,16 +36,16 @@ namespace TdApp
});
_client = Td.Client.Create(_handler);
var parameters = new TdApi.TdlibParameters();
parameters.DatabaseDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
parameters.UseSecretChats = true;
parameters.UseMessageDatabase = true;
parameters.ApiId = 94575;
parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters.SystemLanguageCode = "en";
parameters.DeviceModel = "Desktop";
parameters.ApplicationVersion = "1.0.0";
_client.Send(new TdApi.SetTdlibParameters(parameters), null);
var request = new TdApi.SetTdlibParameters();
request.DatabaseDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
request.UseSecretChats = true;
request.UseMessageDatabase = true;
request.ApiId = 94575;
request.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
request.SystemLanguageCode = "en";
request.DeviceModel = "Desktop";
request.ApplicationVersion = "1.0.0";
_client.Send(request, null);
}
public void Print(String str)

View File

@ -734,14 +734,14 @@ class TdClient {
prepareQuery(query) {
if (query['@type'] === 'setTdlibParameters') {
query.parameters.database_directory = this.tdfs.dbFileSystem.root;
query.parameters.files_directory = this.tdfs.inboundFileSystem.root;
query.database_directory = this.tdfs.dbFileSystem.root;
query.files_directory = this.tdfs.inboundFileSystem.root;
const useDb = this.useDatabase;
query.parameters.use_file_database = useDb;
query.parameters.use_chat_info_database = useDb;
query.parameters.use_message_database = useDb;
query.parameters.use_secret_chats = useDb;
query.use_file_database = useDb;
query.use_chat_info_database = useDb;
query.use_message_database = useDb;
query.use_secret_chats = useDb;
}
if (query['@type'] === 'getLanguagePackString') {
query.language_pack_database_path =

View File

@ -22,26 +22,6 @@ error code:int32 message:string = Error;
ok = Ok;
//@description Contains parameters for TDLib initialization
//@use_test_dc If set to true, the Telegram test environment will be used instead of the production environment
//@database_directory The path to the directory for the persistent database; if empty, the current working directory will be used
//@files_directory The path to the directory for storing files; if empty, database_directory will be used
//@database_encryption_key Encryption key for the database
//@use_file_database If set to true, information about downloaded and uploaded files will be saved between application restarts
//@use_chat_info_database If set to true, the library will maintain a cache of users, basic groups, supergroups, channels and secret chats. Implies use_file_database
//@use_message_database If set to true, the library will maintain a cache of chats and messages. Implies use_chat_info_database
//@use_secret_chats If set to true, support for secret chats will be enabled
//@api_id Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
//@api_hash Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
//@system_language_code IETF language tag of the user's operating system language; must be non-empty
//@device_model Model of the device the application is being run on; must be non-empty
//@system_version Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
//@application_version Application version; must be non-empty
//@enable_storage_optimizer If set to true, old files will automatically be deleted
//@ignore_file_names If set to true, original file names will be ignored. Otherwise, downloaded files will be saved under names as close as possible to the original name
tdlibParameters use_test_dc:Bool database_directory:string files_directory:string database_encryption_key:bytes use_file_database:Bool use_chat_info_database:Bool use_message_database:Bool use_secret_chats:Bool api_id:int32 api_hash:string system_language_code:string device_model:string system_version:string application_version:string enable_storage_optimizer:Bool ignore_file_names:Bool = TdlibParameters;
//@class AuthenticationCodeType @description Provides information about the method by which an authentication code is delivered to the user
//@description An authentication code is delivered via a private Telegram message, which can be viewed from another active session @length Length of the code
@ -96,7 +76,7 @@ termsOfService text:formattedText min_user_age:int32 show_popup:Bool = TermsOfSe
//@class AuthorizationState @description Represents the current authorization state of the TDLib client
//@description TDLib needs TdlibParameters for initialization
//@description Initializetion parameters are needed. Call `setTdlibParameters` to provide them
authorizationStateWaitTdlibParameters = AuthorizationState;
//@description TDLib needs the user's phone number to authorize. Call `setAuthenticationPhoneNumber` to provide the phone number, or use `requestQrCodeAuthentication`, or `checkAuthenticationBotToken` for other authentication options
@ -4624,8 +4604,24 @@ testVectorStringObject value:vector<testString> = TestVectorStringObject;
getAuthorizationState = AuthorizationState;
//@description Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters @parameters Parameters for TDLib initialization
setTdlibParameters parameters:tdlibParameters = Ok;
//@description Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters
//@use_test_dc Pass true to use Telegram test environment instead of the production environment
//@database_directory The path to the directory for the persistent database; if empty, the current working directory will be used
//@files_directory The path to the directory for storing files; if empty, database_directory will be used
//@database_encryption_key Encryption key for the database
//@use_file_database Pass true to keep information about downloaded and uploaded files between application restarts
//@use_chat_info_database Pass true to keep cache of users, basic groups, supergroups, channels and secret chats between restarts. Implies use_file_database
//@use_message_database Pass true to keep cache of chats and messages between restarts. Implies use_chat_info_database
//@use_secret_chats Pass true to enable support for secret chats
//@api_id Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
//@api_hash Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
//@system_language_code IETF language tag of the user's operating system language; must be non-empty
//@device_model Model of the device the application is being run on; must be non-empty
//@system_version Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
//@application_version Application version; must be non-empty
//@enable_storage_optimizer Pass true to automatically delete old files in background
//@ignore_file_names Pass true to ignore original file names for downloaded files. Otherwise, downloaded files are saved under names as close as possible to the original name
setTdlibParameters use_test_dc:Bool database_directory:string files_directory:string database_encryption_key:bytes use_file_database:Bool use_chat_info_database:Bool use_message_database:Bool use_secret_chats:Bool api_id:int32 api_hash:string system_language_code:string device_model:string system_version:string application_version:string enable_storage_optimizer:Bool ignore_file_names:Bool = Ok;
//@description Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber,
//-or if there is no pending authentication query and the current authorization state is authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword

View File

@ -2982,7 +2982,8 @@ void Td::run_request(uint64 id, tl_object_ptr<td_api::Function> function) {
case State::WaitParameters: {
switch (function_id) {
case td_api::setTdlibParameters::ID: {
auto status = set_parameters(std::move(move_tl_object_as<td_api::setTdlibParameters>(function)->parameters_));
auto parameters = move_tl_object_as<td_api::setTdlibParameters>(function);
auto status = set_parameters(std::move(parameters));
if (status.is_error()) {
return send_closure(actor_id(this), &Td::send_error, id, std::move(status));
}
@ -4096,7 +4097,7 @@ Status Td::fix_parameters(TdParameters &parameters) {
return Status::OK();
}
Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) {
Status Td::set_parameters(td_api::object_ptr<td_api::setTdlibParameters> parameters) {
VLOG(td_init) << "Begin to set TDLib parameters";
if (parameters == nullptr) {
VLOG(td_init) << "Empty parameters";

View File

@ -1481,7 +1481,7 @@ class Td final : public Actor {
static Status fix_parameters(TdParameters &parameters) TD_WARN_UNUSED_RESULT;
Status set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) TD_WARN_UNUSED_RESULT;
Status set_parameters(td_api::object_ptr<td_api::setTdlibParameters> parameters) TD_WARN_UNUSED_RESULT;
static td_api::object_ptr<td_api::error> make_error(int32 code, CSlice error) {
return td_api::make_object<td_api::error>(code, error.str());

View File

@ -400,19 +400,19 @@ class CliClient final : public Actor {
authorization_state_ = std::move(state);
switch (authorization_state_->get_id()) {
case td_api::authorizationStateWaitTdlibParameters::ID: {
auto parameters = td_api::make_object<td_api::tdlibParameters>();
parameters->use_test_dc_ = use_test_dc_;
parameters->use_message_database_ = true;
parameters->use_chat_info_database_ = true;
parameters->use_secret_chats_ = true;
parameters->api_id_ = api_id_;
parameters->api_hash_ = api_hash_;
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->application_version_ = "1.0";
auto request = td_api::make_object<td_api::setTdlibParameters>();
request->use_test_dc_ = use_test_dc_;
request->use_message_database_ = true;
request->use_chat_info_database_ = true;
request->use_secret_chats_ = true;
request->api_id_ = api_id_;
request->api_hash_ = api_hash_;
request->system_language_code_ = "en";
request->device_model_ = "Desktop";
request->application_version_ = "1.0";
send_request(
td_api::make_object<td_api::setOption>("use_pfs", td_api::make_object<td_api::optionValueBoolean>(true)));
send_request(td_api::make_object<td_api::setTdlibParameters>(std::move(parameters)));
send_request(std::move(request));
break;
}
case td_api::authorizationStateReady::ID:
@ -1162,11 +1162,11 @@ class CliClient final : public Actor {
td_api::make_object<td_api::proxyTypeSocks5>()));
send_request(td_api::make_object<td_api::pingProxy>(0));
auto bad_parameters = td_api::make_object<td_api::tdlibParameters>();
bad_parameters->database_directory_ = "/..";
bad_parameters->api_id_ = api_id_;
bad_parameters->api_hash_ = api_hash_;
send_request(td_api::make_object<td_api::setTdlibParameters>(std::move(bad_parameters)));
auto bad_request = td_api::make_object<td_api::setTdlibParameters>();
bad_request->database_directory_ = "/..";
bad_request->api_id_ = api_id_;
bad_request->api_hash_ = api_hash_;
send_request(std::move(bad_request));
}
}

View File

@ -235,19 +235,18 @@ class InitTask : public Task {
stop();
break;
case td::td_api::authorizationStateWaitTdlibParameters::ID: {
auto parameters = td::td_api::make_object<td::td_api::tdlibParameters>();
parameters->use_test_dc_ = true;
parameters->database_directory_ = options_.name + TD_DIR_SLASH;
parameters->use_message_database_ = true;
parameters->use_secret_chats_ = true;
parameters->api_id_ = options_.api_id;
parameters->api_hash_ = options_.api_hash;
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->application_version_ = "tdclient-test";
parameters->ignore_file_names_ = false;
parameters->enable_storage_optimizer_ = true;
send(td::td_api::make_object<td::td_api::setTdlibParameters>(std::move(parameters)));
auto request = td::td_api::make_object<td::td_api::setTdlibParameters>();
request->use_test_dc_ = true;
request->database_directory_ = options_.name + TD_DIR_SLASH;
request->use_message_database_ = true;
request->use_secret_chats_ = true;
request->api_id_ = options_.api_id;
request->api_hash_ = options_.api_hash;
request->system_language_code_ = "en";
request->device_model_ = "Desktop";
request->application_version_ = "tdclient-test";
request->enable_storage_optimizer_ = true;
send(std::move(request));
break;
}
default:

View File

@ -221,19 +221,18 @@ class DoAuthentication final : public TestClinetTask {
function = td::make_tl_object<td::td_api::registerUser>(name_, "");
break;
case td::td_api::authorizationStateWaitTdlibParameters::ID: {
auto parameters = td::td_api::make_object<td::td_api::tdlibParameters>();
parameters->use_test_dc_ = true;
parameters->database_directory_ = name_ + TD_DIR_SLASH;
parameters->use_message_database_ = true;
parameters->use_secret_chats_ = true;
parameters->api_id_ = 94575;
parameters->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->application_version_ = "tdclient-test";
parameters->ignore_file_names_ = false;
parameters->enable_storage_optimizer_ = true;
function = td::td_api::make_object<td::td_api::setTdlibParameters>(std::move(parameters));
auto request = td::td_api::make_object<td::td_api::setTdlibParameters>();
request->use_test_dc_ = true;
request->database_directory_ = name_ + TD_DIR_SLASH;
request->use_message_database_ = true;
request->use_secret_chats_ = true;
request->api_id_ = 94575;
request->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
request->system_language_code_ = "en";
request->device_model_ = "Desktop";
request->application_version_ = "tdclient-test";
request->enable_storage_optimizer_ = true;
function = std::move(request);
break;
}
case td::td_api::authorizationStateReady::ID: