From 180679935798516f82150aeb605050ce2f70d227 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 12 Apr 2024 00:45:32 +0300 Subject: [PATCH] Add td_api::getBusinessChatLinkInfo. --- td/generate/scheme/td_api.tl | 8 +++++ td/telegram/BusinessManager.cpp | 54 +++++++++++++++++++++++++++++++++ td/telegram/BusinessManager.h | 3 ++ td/telegram/Td.cpp | 7 +++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 76 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 6d84b4a5a..2d9a260bb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -674,6 +674,11 @@ businessChatLinks links:vector = BusinessChatLinks; //@title Link title inputBusinessChatLink text:formattedText title:string = InputBusinessChatLink; +//@description Contains information about a business chat link +//@chat_id Identifier of the private chat that created the link +//@text Message draft text that must be added to the input field +businessChatLinkInfo chat_id:int53 text:formattedText = BusinessChatLinkInfo; + //@class ChatPhotoStickerType @description Describes type of sticker, which was used to create a chat photo @@ -9784,6 +9789,9 @@ editBusinessChatLink link:string link_info:inputBusinessChatLink = BusinessChatL //@description Deletes a business chat link of the current account @link The link to delete deleteBusinessChatLink link:string = Ok; +//@description Returns information about a business chat link @link The link +getBusinessChatLinkInfo link:string = BusinessChatLinkInfo; + //@description Returns an HTTPS link, which can be used to get information about the current user getUserLink = UserLink; diff --git a/td/telegram/BusinessManager.cpp b/td/telegram/BusinessManager.cpp index b1379201d..a84e44a6a 100644 --- a/td/telegram/BusinessManager.cpp +++ b/td/telegram/BusinessManager.cpp @@ -19,6 +19,7 @@ #include "td/telegram/DialogManager.h" #include "td/telegram/Global.h" #include "td/telegram/InputBusinessChatLink.h" +#include "td/telegram/MessageEntity.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/Td.h" #include "td/telegram/telegram_api.h" @@ -305,6 +306,54 @@ class DeleteBusinessChatLinkQuery final : public Td::ResultHandler { } }; +class ResolveBusinessChatLinkQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit ResolveBusinessChatLinkQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(const string &link) { + send_query(G()->net_query_creator().create(telegram_api::account_resolveBusinessChatLink(link), {{"me"}})); + } + + 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()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for ResolveBusinessChatLinkQuery: " << to_string(ptr); + td_->user_manager_->on_get_users(std::move(ptr->users_), "ResolveBusinessChatLinkQuery"); + td_->chat_manager_->on_get_chats(std::move(ptr->chats_), "ResolveBusinessChatLinkQuery"); + + auto text = get_message_text(td_->user_manager_.get(), std::move(ptr->message_), std::move(ptr->entities_), true, true, 0, false, "ResolveBusinessChatLinkQuery"); + if (text.text[0] == '@') { + text.text = ' ' + text.text; + for (auto &entity : text.entities) { + entity.offset++; + } + } + DialogId dialog_id(ptr->peer_); + if (dialog_id.get_type() != DialogType::User) { + LOG(ERROR) << "Receive " << dialog_id; + return on_error(Status::Error(500, "Receive invalid business chat")); + } + remove_unallowed_entities(td_, text, dialog_id); + td_->dialog_manager_->force_create_dialog(dialog_id, "ResolveBusinessChatLinkQuery"); + + promise_.set_value(td_api::make_object( + td_->dialog_manager_->get_chat_id_object(dialog_id, "businessChatLinkInfo"), + get_formatted_text_object(text, true, -1))); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class UpdateBusinessLocationQuery final : public Td::ResultHandler { Promise promise_; DialogLocation location_; @@ -552,6 +601,11 @@ void BusinessManager::delete_business_chat_link(const string &link, Promisecreate_handler(std::move(promise))->send(link); } +void BusinessManager::get_business_chat_link_info(const string &link, + Promise> &&promise) { + td_->create_handler(std::move(promise))->send(link); +} + void BusinessManager::set_business_location(DialogLocation &&location, Promise &&promise) { td_->create_handler(std::move(promise))->send(std::move(location)); } diff --git a/td/telegram/BusinessManager.h b/td/telegram/BusinessManager.h index ec0299c43..d915b1f93 100644 --- a/td/telegram/BusinessManager.h +++ b/td/telegram/BusinessManager.h @@ -48,6 +48,9 @@ class BusinessManager final : public Actor { void delete_business_chat_link(const string &link, Promise &&promise); + void get_business_chat_link_info(const string &link, + Promise> &&promise); + void set_business_location(DialogLocation &&location, Promise &&promise); void set_business_work_hours(BusinessWorkHours &&work_hours, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0db36ed9a..d39a6b21c 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -8011,6 +8011,13 @@ void Td::on_request(uint64 id, td_api::deleteBusinessChatLink &request) { business_manager_->delete_business_chat_link(request.link_, std::move(promise)); } +void Td::on_request(uint64 id, td_api::getBusinessChatLinkInfo &request) { + CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.link_); + CREATE_REQUEST_PROMISE(); + business_manager_->get_business_chat_link_info(request.link_, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.username_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index add345173..f03a8d8da 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1451,6 +1451,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::deleteBusinessChatLink &request); + void on_request(uint64 id, td_api::getBusinessChatLinkInfo &request); + void on_request(uint64 id, td_api::setSupergroupUsername &request); void on_request(uint64 id, td_api::toggleSupergroupUsernameIsActive &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 18dc0e054..45adddce9 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -6186,6 +6186,8 @@ class CliClient final : public Actor { link, td_api::make_object(as_formatted_text(text), title))); } else if (op == "dbcl") { send_request(td_api::make_object(args)); + } else if (op == "gbcli") { + send_request(td_api::make_object(args)); } else if (op == "gbc") { send_request(td_api::make_object(args.empty() ? business_connection_id_ : args)); } else if (op == "sco") {