From d3ef57e961c453d7f8109006c3d89cf57de2624b Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Mar 2023 13:54:04 +0300 Subject: [PATCH] Add td_api::getSupportName. --- td/generate/scheme/td_api.tl | 3 +++ td/telegram/Support.cpp | 29 +++++++++++++++++++++++++++++ td/telegram/Support.h | 2 ++ td/telegram/Td.cpp | 13 +++++++++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 51 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 229ae306f..a65917526 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -8296,6 +8296,9 @@ getUserSupportInfo user_id:int53 = UserSupportInfo; //@description Sets support information for the given user; for Telegram support only @user_id User identifier @message New information message setUserSupportInfo user_id:int53 message:formattedText = UserSupportInfo; +//@description Returns localized name of the Telegram support user; for Telegram support only +getSupportName = Text; + //@description Does nothing; for testing only. This is an offline method. Can be called before authorization testCallEmpty = Ok; diff --git a/td/telegram/Support.cpp b/td/telegram/Support.cpp index 50978286a..191a10a63 100644 --- a/td/telegram/Support.cpp +++ b/td/telegram/Support.cpp @@ -98,6 +98,31 @@ class EditUserInfoQuery final : public Td::ResultHandler { } }; +class GetSupportNameQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit GetSupportNameQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::help_getSupportName())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + promise_.set_value(std::move(result_ptr.ok_ref()->name_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + void get_user_info(Td *td, UserId user_id, Promise> &&promise) { td->create_handler(std::move(promise))->send(user_id); } @@ -110,4 +135,8 @@ void set_user_info(Td *td, UserId user_id, td_api::object_ptrcreate_handler(std::move(promise))->send(user_id, std::move(formatted_text)); } +void get_support_name(Td *td, Promise &&promise) { + td->create_handler(std::move(promise))->send(); +} + } // namespace td diff --git a/td/telegram/Support.h b/td/telegram/Support.h index 17dd51cba..e0265fb66 100644 --- a/td/telegram/Support.h +++ b/td/telegram/Support.h @@ -21,4 +21,6 @@ void get_user_info(Td *td, UserId user_id, Promise &&message, Promise> &&promise); +void get_support_name(Td *td, Promise &&promise); + } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7a0354802..120a85ddb 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -8462,6 +8462,19 @@ void Td::on_request(uint64 id, td_api::setUserSupportInfo &request) { set_user_info(this, UserId(request.user_id_), std::move(request.message_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getSupportName &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(make_tl_object(result.move_as_ok())); + } + }); + get_support_name(this, std::move(query_promise)); +} + void Td::on_request(uint64 id, const td_api::getTextEntities &request) { UNREACHABLE(); } diff --git a/td/telegram/Td.h b/td/telegram/Td.h index f64895f09..4e629ec83 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1507,6 +1507,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setUserSupportInfo &request); + void on_request(uint64 id, const td_api::getSupportName &request); + void on_request(uint64 id, const td_api::getTextEntities &request); void on_request(uint64 id, const td_api::parseTextEntities &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d2699d2e1..47cc80ad9 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5297,6 +5297,8 @@ class CliClient final : public Actor { string text; get_args(args, user_id, text); send_request(td_api::make_object(user_id, as_formatted_text(text))); + } else if (op == "gsn") { + send_request(td_api::make_object()); } else if (op == "touch") { auto r_fd = FileFd::open(args, FileFd::Read | FileFd::Write); if (r_fd.is_error()) {