Add td_api::toggleBotIsAddedToAttachMenu.
This commit is contained in:
parent
515000f875
commit
c6f6733669
@ -5119,6 +5119,10 @@ toggleChatIsPinned chat_list:ChatList chat_id:int53 is_pinned:Bool = Ok;
|
|||||||
setPinnedChats chat_list:ChatList chat_ids:vector<int53> = Ok;
|
setPinnedChats chat_list:ChatList chat_ids:vector<int53> = Ok;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Adds or removes a bot to attach menu. Bot can be added to attach menu, only if userTypeBot.can_be_added_to_attach_menu == true @bot_user_id Bot's user identifier @is_added Pass true to add the bot to attach menu; pass false to remove the bot from attach menu
|
||||||
|
toggleBotIsAddedToAttachMenu bot_user_id:int53 is_added:Bool = Ok;
|
||||||
|
|
||||||
|
|
||||||
//@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates
|
//@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates
|
||||||
//@file_id Identifier of the file to download
|
//@file_id Identifier of the file to download
|
||||||
//@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first
|
//@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/TdDb.h"
|
#include "td/telegram/TdDb.h"
|
||||||
|
|
||||||
#include "td/actor/PromiseFuture.h"
|
|
||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
@ -56,6 +54,36 @@ class GetAttachMenuBotsQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ToggleBotInAttachMenuQuery final : public Td::ResultHandler {
|
||||||
|
Promise<Unit> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ToggleBotInAttachMenuQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(tl_object_ptr<telegram_api::InputUser> &&input_user, bool is_added) {
|
||||||
|
send_query(
|
||||||
|
G()->net_query_creator().create(telegram_api::messages_toggleBotInAttachMenu(std::move(input_user), is_added)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_toggleBotInAttachMenu>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = result_ptr.move_as_ok();
|
||||||
|
if (!result) {
|
||||||
|
LOG(ERROR) << "Failed to add a bot to attach menu";
|
||||||
|
}
|
||||||
|
promise_.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bool operator==(const AttachMenuManager::AttachMenuBot &lhs, const AttachMenuManager::AttachMenuBot &rhs) {
|
bool operator==(const AttachMenuManager::AttachMenuBot &lhs, const AttachMenuManager::AttachMenuBot &rhs) {
|
||||||
return lhs.user_id_ == rhs.user_id_ && lhs.name_ == rhs.name_ &&
|
return lhs.user_id_ == rhs.user_id_ && lhs.name_ == rhs.name_ &&
|
||||||
lhs.default_icon_file_id_ == rhs.default_icon_file_id_ &&
|
lhs.default_icon_file_id_ == rhs.default_icon_file_id_ &&
|
||||||
@ -321,6 +349,32 @@ void AttachMenuManager::on_reload_attach_menu_bots(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttachMenuManager::toggle_bot_is_added_to_attach_menu(UserId user_id, bool is_added, Promise<Unit> &&promise) {
|
||||||
|
CHECK(is_active());
|
||||||
|
|
||||||
|
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id));
|
||||||
|
|
||||||
|
bool is_found = false;
|
||||||
|
for (auto &bot : attach_menu_bots_) {
|
||||||
|
if (bot.user_id_ == user_id) {
|
||||||
|
is_found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_added == is_found) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_added) {
|
||||||
|
TRY_RESULT_PROMISE(promise, bot_data, td_->contacts_manager_->get_bot_data(user_id));
|
||||||
|
if (!bot_data.can_be_added_to_attach_menu) {
|
||||||
|
return promise.set_error(Status::Error(400, "The bot can't be added to attach menu"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
td_->create_handler<ToggleBotInAttachMenuQuery>(std::move(promise))->send(std::move(input_user), is_added);
|
||||||
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::updateAttachMenuBots> AttachMenuManager::get_update_attach_menu_bots_object() const {
|
td_api::object_ptr<td_api::updateAttachMenuBots> AttachMenuManager::get_update_attach_menu_bots_object() const {
|
||||||
CHECK(is_active());
|
CHECK(is_active());
|
||||||
CHECK(is_inited_);
|
CHECK(is_inited_);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "td/telegram/UserId.h"
|
#include "td/telegram/UserId.h"
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
#include "td/actor/actor.h"
|
||||||
|
#include "td/actor/PromiseFuture.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
@ -26,11 +27,11 @@ class AttachMenuManager final : public Actor {
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
||||||
|
|
||||||
void reload_attach_menu_bots();
|
void reload_attach_menu_bots();
|
||||||
|
|
||||||
void on_reload_attach_menu_bots(Result<telegram_api::object_ptr<telegram_api::AttachMenuBots>> &&result);
|
void toggle_bot_is_added_to_attach_menu(UserId user_id, bool is_added, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void start_up() final;
|
void start_up() final;
|
||||||
@ -71,6 +72,8 @@ class AttachMenuManager final : public Actor {
|
|||||||
|
|
||||||
void save_attach_menu_bots();
|
void save_attach_menu_bots();
|
||||||
|
|
||||||
|
void on_reload_attach_menu_bots(Result<telegram_api::object_ptr<telegram_api::AttachMenuBots>> &&result);
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
|
|
||||||
|
@ -6120,6 +6120,13 @@ void Td::on_request(uint64 id, const td_api::setPinnedChats &request) {
|
|||||||
transform(request.chat_ids_, [](int64 chat_id) { return DialogId(chat_id); })));
|
transform(request.chat_ids_, [](int64 chat_id) { return DialogId(chat_id); })));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::toggleBotIsAddedToAttachMenu &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
|
attach_menu_manager_->toggle_bot_is_added_to_attach_menu(UserId(request.bot_user_id_), request.is_added_,
|
||||||
|
std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::setChatAvailableReactions &request) {
|
void Td::on_request(uint64 id, td_api::setChatAvailableReactions &request) {
|
||||||
for (auto &reaction : request.available_reactions_) {
|
for (auto &reaction : request.available_reactions_) {
|
||||||
CLEAN_INPUT_STRING(reaction);
|
CLEAN_INPUT_STRING(reaction);
|
||||||
|
@ -843,6 +843,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::setPinnedChats &request);
|
void on_request(uint64 id, const td_api::setPinnedChats &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachMenu &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::setChatAvailableReactions &request);
|
void on_request(uint64 id, td_api::setChatAvailableReactions &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::setChatClientData &request);
|
void on_request(uint64 id, td_api::setChatClientData &request);
|
||||||
|
@ -3414,6 +3414,11 @@ class CliClient final : public Actor {
|
|||||||
td_api::make_object<td_api::toggleChatDefaultDisableNotification>(chat_id, default_disable_notification));
|
td_api::make_object<td_api::toggleChatDefaultDisableNotification>(chat_id, default_disable_notification));
|
||||||
} else if (op == "spchats" || op == "spchatsa" || begins_with(op, "spchats-")) {
|
} else if (op == "spchats" || op == "spchatsa" || begins_with(op, "spchats-")) {
|
||||||
send_request(td_api::make_object<td_api::setPinnedChats>(as_chat_list(op), as_chat_ids(args)));
|
send_request(td_api::make_object<td_api::setPinnedChats>(as_chat_list(op), as_chat_ids(args)));
|
||||||
|
} else if (op == "tbiatam") {
|
||||||
|
UserId user_id;
|
||||||
|
bool is_added;
|
||||||
|
get_args(args, user_id, is_added);
|
||||||
|
send_request(td_api::make_object<td_api::toggleBotIsAddedToAttachMenu>(user_id, is_added));
|
||||||
} else if (op == "sca") {
|
} else if (op == "sca") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
string message_thread_id;
|
string message_thread_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user