Add td_api::getBusinessChatLinkInfo.

This commit is contained in:
levlam 2024-04-12 00:45:32 +03:00
parent 9d95eb4a68
commit 1806799357
6 changed files with 76 additions and 0 deletions

View File

@ -674,6 +674,11 @@ businessChatLinks links:vector<businessChatLink> = BusinessChatLinks;
//@title Link title //@title Link title
inputBusinessChatLink text:formattedText title:string = InputBusinessChatLink; 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 //@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 //@description Deletes a business chat link of the current account @link The link to delete
deleteBusinessChatLink link:string = Ok; 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 //@description Returns an HTTPS link, which can be used to get information about the current user
getUserLink = UserLink; getUserLink = UserLink;

View File

@ -19,6 +19,7 @@
#include "td/telegram/DialogManager.h" #include "td/telegram/DialogManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/InputBusinessChatLink.h" #include "td/telegram/InputBusinessChatLink.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessagesManager.h" #include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
@ -305,6 +306,54 @@ class DeleteBusinessChatLinkQuery final : public Td::ResultHandler {
} }
}; };
class ResolveBusinessChatLinkQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::businessChatLinkInfo>> promise_;
public:
explicit ResolveBusinessChatLinkQuery(Promise<td_api::object_ptr<td_api::businessChatLinkInfo>> &&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<telegram_api::account_resolveBusinessChatLink>(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_api::businessChatLinkInfo>(
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 { class UpdateBusinessLocationQuery final : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
DialogLocation location_; DialogLocation location_;
@ -552,6 +601,11 @@ void BusinessManager::delete_business_chat_link(const string &link, Promise<Unit
td_->create_handler<DeleteBusinessChatLinkQuery>(std::move(promise))->send(link); td_->create_handler<DeleteBusinessChatLinkQuery>(std::move(promise))->send(link);
} }
void BusinessManager::get_business_chat_link_info(const string &link,
Promise<td_api::object_ptr<td_api::businessChatLinkInfo>> &&promise) {
td_->create_handler<ResolveBusinessChatLinkQuery>(std::move(promise))->send(link);
}
void BusinessManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) { void BusinessManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location)); td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location));
} }

View File

@ -48,6 +48,9 @@ class BusinessManager final : public Actor {
void delete_business_chat_link(const string &link, Promise<Unit> &&promise); void delete_business_chat_link(const string &link, Promise<Unit> &&promise);
void get_business_chat_link_info(const string &link,
Promise<td_api::object_ptr<td_api::businessChatLinkInfo>> &&promise);
void set_business_location(DialogLocation &&location, Promise<Unit> &&promise); void set_business_location(DialogLocation &&location, Promise<Unit> &&promise);
void set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise); void set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise);

View File

@ -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)); 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) { void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.username_); CLEAN_INPUT_STRING(request.username_);

View File

@ -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::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::setSupergroupUsername &request);
void on_request(uint64 id, td_api::toggleSupergroupUsernameIsActive &request); void on_request(uint64 id, td_api::toggleSupergroupUsernameIsActive &request);

View File

@ -6186,6 +6186,8 @@ class CliClient final : public Actor {
link, td_api::make_object<td_api::inputBusinessChatLink>(as_formatted_text(text), title))); link, td_api::make_object<td_api::inputBusinessChatLink>(as_formatted_text(text), title)));
} else if (op == "dbcl") { } else if (op == "dbcl") {
send_request(td_api::make_object<td_api::deleteBusinessChatLink>(args)); send_request(td_api::make_object<td_api::deleteBusinessChatLink>(args));
} else if (op == "gbcli") {
send_request(td_api::make_object<td_api::getBusinessChatLinkInfo>(args));
} else if (op == "gbc") { } else if (op == "gbc") {
send_request(td_api::make_object<td_api::getBusinessConnection>(args.empty() ? business_connection_id_ : args)); send_request(td_api::make_object<td_api::getBusinessConnection>(args.empty() ? business_connection_id_ : args));
} else if (op == "sco") { } else if (op == "sco") {