Skip to content

Commit f6a2ecd

Browse files
committed
Inline tdlibParameters in setTdlibParameters.
1 parent ebb6770 commit f6a2ecd

File tree

13 files changed

+132
-140
lines changed

13 files changed

+132
-140
lines changed

example/cpp/td_example.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,17 @@ class TdExample {
290290
create_authentication_query_handler());
291291
},
292292
[this](td_api::authorizationStateWaitTdlibParameters &) {
293-
auto parameters = td_api::make_object<td_api::tdlibParameters>();
294-
parameters->database_directory_ = "tdlib";
295-
parameters->use_message_database_ = true;
296-
parameters->use_secret_chats_ = true;
297-
parameters->api_id_ = 94575;
298-
parameters->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
299-
parameters->system_language_code_ = "en";
300-
parameters->device_model_ = "Desktop";
301-
parameters->application_version_ = "1.0";
302-
parameters->enable_storage_optimizer_ = true;
303-
send_query(td_api::make_object<td_api::setTdlibParameters>(std::move(parameters)),
304-
create_authentication_query_handler());
293+
auto request = td_api::make_object<td_api::setTdlibParameters>();
294+
request->database_directory_ = "tdlib";
295+
request->use_message_database_ = true;
296+
request->use_secret_chats_ = true;
297+
request->api_id_ = 94575;
298+
request->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
299+
request->system_language_code_ = "en";
300+
request->device_model_ = "Desktop";
301+
request->application_version_ = "1.0";
302+
request->enable_storage_optimizer_ = true;
303+
send_query(std::move(request), create_authentication_query_handler());
305304
}));
306305
}
307306

example/csharp/TdExample.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ private static void OnAuthorizationStateUpdated(TdApi.AuthorizationState authori
6767
}
6868
if (_authorizationState is TdApi.AuthorizationStateWaitTdlibParameters)
6969
{
70-
TdApi.TdlibParameters parameters = new TdApi.TdlibParameters();
71-
parameters.DatabaseDirectory = "tdlib";
72-
parameters.UseMessageDatabase = true;
73-
parameters.UseSecretChats = true;
74-
parameters.ApiId = 94575;
75-
parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
76-
parameters.SystemLanguageCode = "en";
77-
parameters.DeviceModel = "Desktop";
78-
parameters.ApplicationVersion = "1.0";
79-
parameters.EnableStorageOptimizer = true;
70+
TdApi.SetTdlibParameters request = new TdApi.SetTdlibParameters();
71+
request.DatabaseDirectory = "tdlib";
72+
request.UseMessageDatabase = true;
73+
request.UseSecretChats = true;
74+
request.ApiId = 94575;
75+
request.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
76+
request.SystemLanguageCode = "en";
77+
request.DeviceModel = "Desktop";
78+
request.ApplicationVersion = "1.0";
79+
request.EnableStorageOptimizer = true;
8080

81-
_client.Send(new TdApi.SetTdlibParameters(parameters), new AuthorizationRequestHandler());
81+
_client.Send(request, new AuthorizationRequestHandler());
8282
}
8383
else if (_authorizationState is TdApi.AuthorizationStateWaitPhoneNumber)
8484
{

example/java/org/drinkless/tdlib/example/Example.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ private static void onAuthorizationStateUpdated(TdApi.AuthorizationState authori
101101
}
102102
switch (Example.authorizationState.getConstructor()) {
103103
case TdApi.AuthorizationStateWaitTdlibParameters.CONSTRUCTOR:
104-
TdApi.TdlibParameters parameters = new TdApi.TdlibParameters();
105-
parameters.databaseDirectory = "tdlib";
106-
parameters.useMessageDatabase = true;
107-
parameters.useSecretChats = true;
108-
parameters.apiId = 94575;
109-
parameters.apiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
110-
parameters.systemLanguageCode = "en";
111-
parameters.deviceModel = "Desktop";
112-
parameters.applicationVersion = "1.0";
113-
parameters.enableStorageOptimizer = true;
114-
115-
client.send(new TdApi.SetTdlibParameters(parameters), new AuthorizationRequestHandler());
104+
TdApi.SetTdlibParameters request = new TdApi.SetTdlibParameters();
105+
request.databaseDirectory = "tdlib";
106+
request.useMessageDatabase = true;
107+
request.useSecretChats = true;
108+
request.apiId = 94575;
109+
request.apiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
110+
request.systemLanguageCode = "en";
111+
request.deviceModel = "Desktop";
112+
request.applicationVersion = "1.0";
113+
request.enableStorageOptimizer = true;
114+
115+
client.send(parameters, new AuthorizationRequestHandler());
116116
break;
117117
case TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR: {
118118
String phoneNumber = promptString("Please enter phone number: ");

example/python/tdjson_example.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ def td_receive():
9494
# you MUST obtain your own api_id and api_hash at https://my.telegram.org
9595
# and use them in the setTdlibParameters call
9696
if auth_state['@type'] == 'authorizationStateWaitTdlibParameters':
97-
td_send({'@type': 'setTdlibParameters', 'parameters': {
98-
'database_directory': 'tdlib',
99-
'use_message_database': True,
100-
'use_secret_chats': True,
101-
'api_id': 94575,
102-
'api_hash': 'a3406de8d171bb422bb6ddf3bbd800e2',
103-
'system_language_code': 'en',
104-
'device_model': 'Desktop',
105-
'application_version': '1.0',
106-
'enable_storage_optimizer': True}})
97+
td_send({'@type': 'setTdlibParameters',
98+
'database_directory': 'tdlib',
99+
'use_message_database': True,
100+
'use_secret_chats': True,
101+
'api_id': 94575,
102+
'api_hash': 'a3406de8d171bb422bb6ddf3bbd800e2',
103+
'system_language_code': 'en',
104+
'device_model': 'Desktop',
105+
'application_version': '1.0',
106+
'enable_storage_optimizer': True})
107107

108108
# enter phone number to log in
109109
if auth_state['@type'] == 'authorizationStateWaitPhoneNumber':

example/swift/src/main.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,15 @@ func updateAuthorizationState(authorizationState: Dictionary<String, Any>) {
107107
case "authorizationStateWaitTdlibParameters":
108108
client.queryAsync(query:[
109109
"@type":"setTdlibParameters",
110-
"parameters":[
111-
"database_directory":"tdlib",
112-
"use_message_database":true,
113-
"use_secret_chats":true,
114-
"api_id":94575,
115-
"api_hash":"a3406de8d171bb422bb6ddf3bbd800e2",
116-
"system_language_code":"en",
117-
"device_model":"Desktop",
118-
"application_version":"1.0",
119-
"enable_storage_optimizer":true
120-
]
110+
"database_directory":"tdlib",
111+
"use_message_database":true,
112+
"use_secret_chats":true,
113+
"api_id":94575,
114+
"api_hash":"a3406de8d171bb422bb6ddf3bbd800e2",
115+
"system_language_code":"en",
116+
"device_model":"Desktop",
117+
"application_version":"1.0",
118+
"enable_storage_optimizer":true
121119
]);
122120

123121
case "authorizationStateWaitPhoneNumber":

example/uwp/app/MainPage.xaml.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public MainPage()
3636
});
3737

3838
_client = Td.Client.Create(_handler);
39-
var parameters = new TdApi.TdlibParameters();
40-
parameters.DatabaseDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
41-
parameters.UseSecretChats = true;
42-
parameters.UseMessageDatabase = true;
43-
parameters.ApiId = 94575;
44-
parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
45-
parameters.SystemLanguageCode = "en";
46-
parameters.DeviceModel = "Desktop";
47-
parameters.ApplicationVersion = "1.0.0";
48-
_client.Send(new TdApi.SetTdlibParameters(parameters), null);
39+
var request = new TdApi.SetTdlibParameters();
40+
request.DatabaseDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
41+
request.UseSecretChats = true;
42+
request.UseMessageDatabase = true;
43+
request.ApiId = 94575;
44+
request.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
45+
request.SystemLanguageCode = "en";
46+
request.DeviceModel = "Desktop";
47+
request.ApplicationVersion = "1.0.0";
48+
_client.Send(request, null);
4949
}
5050

5151
public void Print(String str)

example/web/tdweb/src/worker.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,14 +734,14 @@ class TdClient {
734734

735735
prepareQuery(query) {
736736
if (query['@type'] === 'setTdlibParameters') {
737-
query.parameters.database_directory = this.tdfs.dbFileSystem.root;
738-
query.parameters.files_directory = this.tdfs.inboundFileSystem.root;
737+
query.database_directory = this.tdfs.dbFileSystem.root;
738+
query.files_directory = this.tdfs.inboundFileSystem.root;
739739

740740
const useDb = this.useDatabase;
741-
query.parameters.use_file_database = useDb;
742-
query.parameters.use_chat_info_database = useDb;
743-
query.parameters.use_message_database = useDb;
744-
query.parameters.use_secret_chats = useDb;
741+
query.use_file_database = useDb;
742+
query.use_chat_info_database = useDb;
743+
query.use_message_database = useDb;
744+
query.use_secret_chats = useDb;
745745
}
746746
if (query['@type'] === 'getLanguagePackString') {
747747
query.language_pack_database_path =

td/generate/scheme/td_api.tl

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@ error code:int32 message:string = Error;
2222
ok = Ok;
2323

2424

25-
//@description Contains parameters for TDLib initialization
26-
//@use_test_dc If set to true, the Telegram test environment will be used instead of the production environment
27-
//@database_directory The path to the directory for the persistent database; if empty, the current working directory will be used
28-
//@files_directory The path to the directory for storing files; if empty, database_directory will be used
29-
//@database_encryption_key Encryption key for the database
30-
//@use_file_database If set to true, information about downloaded and uploaded files will be saved between application restarts
31-
//@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
32-
//@use_message_database If set to true, the library will maintain a cache of chats and messages. Implies use_chat_info_database
33-
//@use_secret_chats If set to true, support for secret chats will be enabled
34-
//@api_id Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
35-
//@api_hash Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
36-
//@system_language_code IETF language tag of the user's operating system language; must be non-empty
37-
//@device_model Model of the device the application is being run on; must be non-empty
38-
//@system_version Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
39-
//@application_version Application version; must be non-empty
40-
//@enable_storage_optimizer If set to true, old files will automatically be deleted
41-
//@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
42-
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;
43-
44-
4525
//@class AuthenticationCodeType @description Provides information about the method by which an authentication code is delivered to the user
4626

4727
//@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
9676

9777
//@class AuthorizationState @description Represents the current authorization state of the TDLib client
9878

99-
//@description TDLib needs TdlibParameters for initialization
79+
//@description Initializetion parameters are needed. Call `setTdlibParameters` to provide them
10080
authorizationStateWaitTdlibParameters = AuthorizationState;
10181

10282
//@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;
46244604
getAuthorizationState = AuthorizationState;
46254605

46264606

4627-
//@description Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters @parameters Parameters for TDLib initialization
4628-
setTdlibParameters parameters:tdlibParameters = Ok;
4607+
//@description Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters
4608+
//@use_test_dc Pass true to use Telegram test environment instead of the production environment
4609+
//@database_directory The path to the directory for the persistent database; if empty, the current working directory will be used
4610+
//@files_directory The path to the directory for storing files; if empty, database_directory will be used
4611+
//@database_encryption_key Encryption key for the database
4612+
//@use_file_database Pass true to keep information about downloaded and uploaded files between application restarts
4613+
//@use_chat_info_database Pass true to keep cache of users, basic groups, supergroups, channels and secret chats between restarts. Implies use_file_database
4614+
//@use_message_database Pass true to keep cache of chats and messages between restarts. Implies use_chat_info_database
4615+
//@use_secret_chats Pass true to enable support for secret chats
4616+
//@api_id Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
4617+
//@api_hash Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
4618+
//@system_language_code IETF language tag of the user's operating system language; must be non-empty
4619+
//@device_model Model of the device the application is being run on; must be non-empty
4620+
//@system_version Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
4621+
//@application_version Application version; must be non-empty
4622+
//@enable_storage_optimizer Pass true to automatically delete old files in background
4623+
//@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
4624+
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;
46294625

46304626
//@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,
46314627
//-or if there is no pending authentication query and the current authorization state is authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword

td/telegram/Td.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,8 @@ void Td::run_request(uint64 id, tl_object_ptr<td_api::Function> function) {
29822982
case State::WaitParameters: {
29832983
switch (function_id) {
29842984
case td_api::setTdlibParameters::ID: {
2985-
auto status = set_parameters(std::move(move_tl_object_as<td_api::setTdlibParameters>(function)->parameters_));
2985+
auto parameters = move_tl_object_as<td_api::setTdlibParameters>(function);
2986+
auto status = set_parameters(std::move(parameters));
29862987
if (status.is_error()) {
29872988
return send_closure(actor_id(this), &Td::send_error, id, std::move(status));
29882989
}
@@ -4096,7 +4097,7 @@ Status Td::fix_parameters(TdParameters &parameters) {
40964097
return Status::OK();
40974098
}
40984099

4099-
Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) {
4100+
Status Td::set_parameters(td_api::object_ptr<td_api::setTdlibParameters> parameters) {
41004101
VLOG(td_init) << "Begin to set TDLib parameters";
41014102
if (parameters == nullptr) {
41024103
VLOG(td_init) << "Empty parameters";

td/telegram/Td.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ class Td final : public Actor {
14811481

14821482
static Status fix_parameters(TdParameters &parameters) TD_WARN_UNUSED_RESULT;
14831483

1484-
Status set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) TD_WARN_UNUSED_RESULT;
1484+
Status set_parameters(td_api::object_ptr<td_api::setTdlibParameters> parameters) TD_WARN_UNUSED_RESULT;
14851485

14861486
static td_api::object_ptr<td_api::error> make_error(int32 code, CSlice error) {
14871487
return td_api::make_object<td_api::error>(code, error.str());

0 commit comments

Comments
 (0)