Support non-added bots in the list of attachment menu bots.

This commit is contained in:
levlam 2023-09-07 18:04:21 +03:00
parent 3983615646
commit 289c25fd93
2 changed files with 19 additions and 27 deletions

View File

@ -3622,6 +3622,7 @@ attachmentMenuBotColor light_color:int32 dark_color:int32 = AttachmentMenuBotCol
//@supports_channel_chats True, if the bot supports opening from attachment menu in channel chats
//@supports_settings True, if the bot supports "settings_button_pressed" event
//@request_write_access True, if the user must be asked for the permission to send messages to the bot
//@is_added True, if the bot was explicitly added by the user. If the bot isn't added then on the first bot launch toggleBotIsAddedToAttachmentMenu must be called and the bot must be added or removed
//@show_in_attachment_menu True, if the bot must be shown in the attachment menu
//@show_in_side_menu True, if the bot must be shown in the side menu menu
//@show_disclaimer_in_side_menu True, if a disclaimer, why the bot is shown in the side menu, is needed
@ -3634,7 +3635,7 @@ attachmentMenuBotColor light_color:int32 dark_color:int32 = AttachmentMenuBotCol
//@macos_icon Icon for the bot in TGS format for the official native macOS app; may be null
//@icon_color Color to highlight selected icon of the bot if appropriate; may be null
//@web_app_placeholder Default placeholder for opened Web Apps in SVG format; may be null
attachmentMenuBot bot_user_id:int53 supports_self_chat:Bool supports_user_chats:Bool supports_bot_chats:Bool supports_group_chats:Bool supports_channel_chats:Bool supports_settings:Bool request_write_access:Bool show_in_attachment_menu:Bool show_in_side_menu:Bool show_disclaimer_in_side_menu:Bool name:string name_color:attachmentMenuBotColor default_icon:file ios_static_icon:file ios_animated_icon:file android_icon:file macos_icon:file icon_color:attachmentMenuBotColor web_app_placeholder:file = AttachmentMenuBot;
attachmentMenuBot bot_user_id:int53 supports_self_chat:Bool supports_user_chats:Bool supports_bot_chats:Bool supports_group_chats:Bool supports_channel_chats:Bool supports_settings:Bool request_write_access:Bool is_added:Bool show_in_attachment_menu:Bool show_in_side_menu:Bool show_disclaimer_in_side_menu:Bool name:string name_color:attachmentMenuBotColor default_icon:file ios_static_icon:file ios_animated_icon:file android_icon:file macos_icon:file icon_color:attachmentMenuBotColor web_app_placeholder:file = AttachmentMenuBot;
//@description Information about the message sent by answerWebAppQuery @inline_message_id Identifier of the sent inline message, if known
sentWebAppMessage inline_message_id:string = SentWebAppMessage;
@ -7031,7 +7032,7 @@ getWebAppUrl bot_user_id:int53 url:string theme:themeParameters application_name
//@data The data
sendWebAppData bot_user_id:int53 button_text:string data:string = Ok;
//@description Informs TDLib that a Web App is being opened from attachment menu, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an inlineKeyboardButtonTypeWebApp button.
//@description Informs TDLib that a Web App is being opened from the attachment menu, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an inlineKeyboardButtonTypeWebApp button.
//-For each bot, a confirmation alert about data sent to the bot must be shown once
//@chat_id Identifier of the chat in which the Web App is opened. The Web App can't be opened in secret chats
//@bot_user_id Identifier of the bot, providing the Web App

View File

@ -1062,11 +1062,6 @@ void AttachMenuManager::on_reload_attach_menu_bots(
new_hash = 0;
continue;
}
if (!r_attach_menu_bot.ok().is_added_) {
LOG(ERROR) << "Receive non-added attachment menu bot " << r_attach_menu_bot.ok().user_id_;
new_hash = 0;
continue;
}
new_attach_menu_bots.push_back(r_attach_menu_bot.move_as_ok());
}
@ -1162,19 +1157,26 @@ void AttachMenuManager::on_get_attach_menu_bot(
for (auto &old_bot : attach_menu_bots_) {
if (old_bot.user_id_ == user_id) {
is_found = true;
if (old_bot != attach_menu_bot) {
LOG(INFO) << "Update attachment menu bot " << user_id;
old_bot = attach_menu_bot;
send_update_attach_menu_bots();
save_attach_menu_bots();
}
break;
}
}
if (!is_found) {
LOG(INFO) << "Add missing attachment menu bot " << user_id;
}
hash_ = 0;
attach_menu_bots_.insert(attach_menu_bots_.begin(), attach_menu_bot);
send_update_attach_menu_bots();
save_attach_menu_bots();
} else {
remove_bot_from_attach_menu(user_id);
hash_ = 0;
attach_menu_bots_.insert(attach_menu_bots_.begin(), attach_menu_bot);
send_update_attach_menu_bots();
save_attach_menu_bots();
}
}
promise.set_value(get_attachment_menu_bot_object(attach_menu_bot));
}
@ -1211,17 +1213,6 @@ void AttachMenuManager::toggle_bot_is_added_to_attach_menu(UserId user_id, bool
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) {
@ -1263,8 +1254,8 @@ td_api::object_ptr<td_api::attachmentMenuBot> AttachMenuManager::get_attachment_
return td_api::make_object<td_api::attachmentMenuBot>(
td_->contacts_manager_->get_user_id_object(bot.user_id_, "get_attachment_menu_bot_object"),
bot.supports_self_dialog_, bot.supports_user_dialogs_, bot.supports_bot_dialogs_, bot.supports_group_dialogs_,
bot.supports_broadcast_dialogs_, bot.supports_settings_, bot.request_write_access_, bot.show_in_attach_menu_,
bot.show_in_side_menu_, bot.side_menu_disclaimer_needed_, bot.name_,
bot.supports_broadcast_dialogs_, bot.supports_settings_, bot.request_write_access_, bot.is_added_,
bot.show_in_attach_menu_, bot.show_in_side_menu_, bot.side_menu_disclaimer_needed_, bot.name_,
get_attach_menu_bot_color_object(bot.name_color_), get_file(bot.default_icon_file_id_),
get_file(bot.ios_static_icon_file_id_), get_file(bot.ios_animated_icon_file_id_),
get_file(bot.android_icon_file_id_), get_file(bot.macos_icon_file_id_),