diff --git a/CMakeLists.txt b/CMakeLists.txt index 2de6d486..fafb4830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) -project(TDLib VERSION 1.1.4 LANGUAGES CXX C) +project(TDLib VERSION 1.1.5 LANGUAGES CXX C) # Prevent in-source build get_filename_component(TD_REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) diff --git a/README.md b/README.md index 719d8002..f3cb94c9 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ target_link_libraries(YourTarget PRIVATE Td::TdStatic) Or you could install `TDLib` and then reference it in your CMakeLists.txt like this: ``` -find_package(Td 1.1.4 REQUIRED) +find_package(Td 1.1.5 REQUIRED) target_link_libraries(YourTarget PRIVATE Td::TdStatic) ``` See [example/cpp/CMakeLists.txt](https://github.com/tdlib/td/tree/master/example/cpp/CMakeLists.txt). diff --git a/example/cpp/CMakeLists.txt b/example/cpp/CMakeLists.txt index 26e5bae9..6c25b650 100644 --- a/example/cpp/CMakeLists.txt +++ b/example/cpp/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(TdExample VERSION 1.0 LANGUAGES CXX) -find_package(Td 1.1.4 REQUIRED) +find_package(Td 1.1.5 REQUIRED) add_executable(tdjson_example tdjson_example.cpp) target_link_libraries(tdjson_example PRIVATE Td::TdJson) diff --git a/example/uwp/extension.vsixmanifest b/example/uwp/extension.vsixmanifest index 0d7a62f7..6bc523b7 100644 --- a/example/uwp/extension.vsixmanifest +++ b/example/uwp/extension.vsixmanifest @@ -1,6 +1,6 @@ - + TDLib for Universal Windows Platform TDLib is a library for building Telegram clients https://core.telegram.org/tdlib diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 9082e766..a9fa6b55 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2038,7 +2038,7 @@ createTemporaryPassword password:string valid_for:int32 = TemporaryPasswordState getTemporaryPasswordState = TemporaryPasswordState; -//@description Handles a DC_UPDATE push service notification, can be called before authorization @dc Value of the "dc" parameter of the notification @addr Value of the "addr" parameter of the notification +//@description Handles a DC_UPDATE push service notification. Can be called before authorization @dc Value of the "dc" parameter of the notification @addr Value of the "addr" parameter of the notification processDcUpdate dc:string addr:string = Ok; @@ -2258,16 +2258,16 @@ editInlineMessageCaption inline_message_id:string reply_markup:ReplyMarkup capti editInlineMessageReplyMarkup inline_message_id:string reply_markup:ReplyMarkup = Ok; -//@description Returns all entities (mentions, hashtags, bot commands, URLs, and email addresses) contained in the text. This is an offline method. May be called before authorization. Can be called synchronously @text The text in which to look for entites +//@description Returns all entities (mentions, hashtags, bot commands, URLs, and email addresses) contained in the text. This is an offline method. Can be called before authorization. Can be called synchronously @text The text in which to look for entites getTextEntities text:string = TextEntities; -//@description Parses Bold, Italic, Code, Pre, PreCode and TextUrl entities contained in the text. This is an offline method. May be called before authorization. Can be called synchronously @text The text which should be parsed @parse_mode Text parse mode +//@description Parses Bold, Italic, Code, Pre, PreCode and TextUrl entities contained in the text. This is an offline method. Can be called before authorization. Can be called synchronously @text The text which should be parsed @parse_mode Text parse mode parseTextEntities text:string parse_mode:TextParseMode = FormattedText; -//@description Returns the MIME type of a file, guessed by its extension. Returns an empty string on failure. This is an offline method. May be called before authorization. Can be called synchronously @file_name The name of the file or path to the file +//@description Returns the MIME type of a file, guessed by its extension. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @file_name The name of the file or path to the file getFileMimeType file_name:string = Text; -//@description Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. This is an offline method. May be called before authorization. Can be called synchronously @mime_type The MIME type of the file +//@description Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @mime_type The MIME type of the file getFileExtension mime_type:string = Text; @@ -2734,11 +2734,11 @@ setUserPrivacySettingRules setting:UserPrivacySetting rules:userPrivacySettingRu getUserPrivacySettingRules setting:UserPrivacySetting = UserPrivacySettingRules; -//@description Returns the value of an option by its name. (Check the list of available options on https://core.telegram.org/tdlib/options.) This method can be called before authorization +//@description Returns the value of an option by its name. (Check the list of available options on https://core.telegram.org/tdlib/options.) Can be called before authorization //@name The name of the option getOption name:string = OptionValue; -//@description Sets the value of an option. (Check the list of available options on https://core.telegram.org/tdlib/options.) Only writable options can be set. This method can be called before authorization +//@description Sets the value of an option. (Check the list of available options on https://core.telegram.org/tdlib/options.) Only writable options can be set. Can be called before authorization //@name The name of the option @value The new value of the option setOption name:string value:OptionValue = Ok; @@ -2827,7 +2827,10 @@ answerCustomQuery custom_query_id:int64 data:string = Ok; setAlarm seconds:double = Ok; -//@description Returns the default text for invitation messages to be used as a placeholder when the current user invites friends to Telegram. +//@description Uses current user IP to found his country. Returns two-letter ISO 3166-1 alpha-2 country code. Can be called before authorization +getCountryCode = Text; + +//@description Returns the default text for invitation messages to be used as a placeholder when the current user invites friends to Telegram getInviteText = Text; //@description Returns the terms of service. Can be called before authorization diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 112114e7..dcf11bdf 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index cc3da61d..454b6467 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -118,7 +118,12 @@ void Td::ResultHandler::send_query(NetQueryPtr query) { } class GetNearestDcQuery : public Td::ResultHandler { + Promise promise_; + public: + explicit GetNearestDcQuery(Promise &&promise) : promise_(std::move(promise)) { + } + void send() { send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getNearestDc()), DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); @@ -129,11 +134,13 @@ class GetNearestDcQuery : public Td::ResultHandler { if (result_ptr.is_error()) { return on_error(id, result_ptr.move_as_error()); } + + promise_.set_value(std::move(result_ptr.ok()->country_)); } void on_error(uint64 id, Status status) override { LOG(ERROR) << "GetNearestDc returned " << status; - status.ignore(); + promise_.set_error(std::move(status)); } }; @@ -419,7 +426,8 @@ class GetTermsOfServiceQuery : public Td::ResultHandler { } void send() { - send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getTermsOfService()))); + send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getTermsOfService()), DcId::main(), + NetQuery::Type::Common, NetQuery::AuthFlag::Off)); } void on_result(uint64 id, BufferSlice packet) override { @@ -3625,6 +3633,31 @@ class AnswerCustomQueryRequest : public RequestOnceActor { } }; +class GetCountryCodeRequest : public RequestActor { + string country_code_; + + void do_run(Promise &&promise) override { + if (get_tries() < 2) { + promise.set_value(std::move(country_code_)); + return; + } + + td->create_handler(std::move(promise))->send(); + } + + void do_set_result(string &&result) override { + country_code_ = std::move(result); + } + + void do_send_result() override { + send_result(make_tl_object(country_code_)); + } + + public: + GetCountryCodeRequest(ActorShared td, uint64 request_id) : RequestActor(std::move(td), request_id) { + } +}; + class GetInviteTextRequest : public RequestActor { string text_; @@ -4471,7 +4504,7 @@ Status Td::init(DbKey key) { VLOG(td_init) << "Ping datacenter"; if (!auth_manager_->is_authorized()) { - create_handler()->send(); + create_handler(Auto())->send(); } else { updates_manager_->get_difference("init"); } @@ -6715,6 +6748,10 @@ void Td::on_request(uint64 id, td_api::removeRecentHashtag &request) { send_closure(hashtag_hints_, &HashtagHints::remove_hashtag, std::move(request.hashtag_), std::move(query_promise)); } +void Td::on_request(uint64 id, const td_api::getCountryCode &request) { + CREATE_NO_ARGS_REQUEST(GetCountryCodeRequest); +} + void Td::on_request(uint64 id, const td_api::getInviteText &request) { CHECK_AUTH(); CHECK_IS_USER(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c227dcc7..d6f61ec2 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -192,7 +192,7 @@ class Td final : public NetQueryCallback { static td_api::object_ptr static_request(td_api::object_ptr function); private: - static constexpr const char *tdlib_version = "1.1.4"; + static constexpr const char *tdlib_version = "1.1.5"; static constexpr int64 ONLINE_ALARM_ID = 0; static constexpr int32 ONLINE_TIMEOUT = 240; static constexpr int64 PING_SERVER_ALARM_ID = -1; @@ -755,6 +755,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::removeRecentHashtag &request); + void on_request(uint64 id, const td_api::getCountryCode &request); + void on_request(uint64 id, const td_api::getInviteText &request); void on_request(uint64 id, const td_api::getTermsOfService &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7382fbff..a52c96fd 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1498,6 +1498,8 @@ class CliClient final : public Actor { send_request(make_tl_object()); } else if (op == "gw") { send_request(make_tl_object()); + } else if (op == "gccode") { + send_request(make_tl_object()); } else if (op == "git") { send_request(make_tl_object()); } else if (op == "gtos") {