diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 23b4da401..823f8e524 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6591,6 +6591,9 @@ addLogMessage verbosity_level:int32 text:string = Ok; //@description Returns support information for the given user; for Telegram support only @user_id User identifier 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 Does nothing; for testing only. This is an offline method. Can be called before authorization testCallEmpty = Ok; diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index e77ef40c9..6d246d044 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -4300,7 +4300,7 @@ Result get_formatted_text(const Td *td, DialogId dialog_id, return FormattedText(); } - return Status::Error(400, "Text can't be empty"); + return Status::Error(400, "Text must be non-empty"); } TRY_RESULT(entities, get_message_entities(td->contacts_manager_.get(), std::move(text->entities_))); diff --git a/td/telegram/Support.cpp b/td/telegram/Support.cpp index 5af50f129..63da2f096 100644 --- a/td/telegram/Support.cpp +++ b/td/telegram/Support.cpp @@ -64,8 +64,49 @@ class GetUserInfoQuery final : public Td::ResultHandler { } }; +class EditUserInfoQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit EditUserInfoQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(UserId user_id, FormattedText &&formatted_text) { + auto r_input_user = td_->contacts_manager_->get_input_user(user_id); + if (r_input_user.is_error()) { + return on_error(r_input_user.move_as_error()); + } + + send_query(G()->net_query_creator().create(telegram_api::help_editUserInfo( + r_input_user.move_as_ok(), formatted_text.text, + get_input_message_entities(td_->contacts_manager_.get(), &formatted_text, "EditUserInfoQuery")))); + } + + 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(get_user_support_info_object(td_, result_ptr.move_as_ok())); + } + + 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); } +void set_user_info(Td *td, UserId user_id, td_api::object_ptr &&message, + Promise> &&promise) { + TRY_RESULT_PROMISE( + promise, formatted_text, + get_formatted_text(td, DialogId(td->contacts_manager_->get_my_id()), std::move(message), false, true, true, false)); + td->create_handler(std::move(promise))->send(user_id, std::move(formatted_text)); +} + } // namespace td diff --git a/td/telegram/Support.h b/td/telegram/Support.h index 21e09e3d3..3c0cb3d9e 100644 --- a/td/telegram/Support.h +++ b/td/telegram/Support.h @@ -18,4 +18,7 @@ class Td; void get_user_info(Td *td, UserId user_id, Promise> &&promise); +void set_user_info(Td *td, UserId user_id, td_api::object_ptr &&message, + Promise> &&promise); + } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 5b0f3473d..0a6fd07f5 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7999,6 +7999,12 @@ void Td::on_request(uint64 id, const td_api::getUserSupportInfo &request) { get_user_info(this, UserId(request.user_id_), std::move(promise)); } +void Td::on_request(uint64 id, td_api::setUserSupportInfo &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + set_user_info(this, UserId(request.user_id_), std::move(request.message_), std::move(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 6e4806af8..9bb01a0a0 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1349,6 +1349,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getUserSupportInfo &request); + void on_request(uint64 id, td_api::setUserSupportInfo &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 309ab1eff..b9eaf86d8 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4824,6 +4824,11 @@ class CliClient final : public Actor { UserId user_id; get_args(args, user_id); send_request(td_api::make_object(user_id)); + } else if (op == "susi") { + UserId user_id; + string text; + get_args(args, user_id, text); + send_request(td_api::make_object(user_id, as_formatted_text(text))); } else if (op == "touch") { auto r_fd = FileFd::open(args, FileFd::Read | FileFd::Write); if (r_fd.is_error()) {