Move on_update_bot_commands to DialogManager.
This commit is contained in:
parent
b1b33cf427
commit
919a1d8329
|
@ -6461,61 +6461,10 @@ void ContactsManager::update_is_location_visible() {
|
|||
td_->option_manager_->set_option_boolean("is_location_visible", expire_date != 0);
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_bot_commands(DialogId dialog_id, UserId bot_user_id,
|
||||
vector<tl_object_ptr<telegram_api::botCommand>> &&bot_commands) {
|
||||
if (!bot_user_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive updateBotCOmmands about invalid " << bot_user_id;
|
||||
return;
|
||||
}
|
||||
if (!have_user(bot_user_id) || !is_user_bot(bot_user_id)) {
|
||||
return;
|
||||
}
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User: {
|
||||
UserId user_id(dialog_id.get_user_id());
|
||||
auto user_full = get_user_full(user_id);
|
||||
if (user_full != nullptr) {
|
||||
on_update_user_full_commands(user_full, user_id, std::move(bot_commands));
|
||||
update_user_full(user_full, user_id, "on_update_bot_commands");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::Chat: {
|
||||
ChatId chat_id(dialog_id.get_chat_id());
|
||||
auto chat_full = get_chat_full(chat_id);
|
||||
if (chat_full != nullptr && BotCommands::update_all_bot_commands(
|
||||
chat_full->bot_commands, BotCommands(bot_user_id, std::move(bot_commands)))) {
|
||||
chat_full->is_changed = true;
|
||||
update_chat_full(chat_full, chat_id, "on_update_bot_commands");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::Channel: {
|
||||
ChannelId channel_id(dialog_id.get_channel_id());
|
||||
auto channel_full = get_channel_full(channel_id, true, "on_update_bot_commands");
|
||||
if (channel_full != nullptr &&
|
||||
BotCommands::update_all_bot_commands(channel_full->bot_commands,
|
||||
BotCommands(bot_user_id, std::move(bot_commands)))) {
|
||||
channel_full->is_changed = true;
|
||||
update_channel_full(channel_full, channel_id, "on_update_bot_commands");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::SecretChat:
|
||||
default:
|
||||
LOG(ERROR) << "Receive updateBotCommands in " << dialog_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_bot_menu_button(UserId bot_user_id,
|
||||
tl_object_ptr<telegram_api::BotMenuButton> &&bot_menu_button) {
|
||||
if (!bot_user_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive updateBotCOmmands about invalid " << bot_user_id;
|
||||
LOG(ERROR) << "Receive updateBotMenuButton about invalid " << bot_user_id;
|
||||
return;
|
||||
}
|
||||
if (!have_user_force(bot_user_id, "on_update_bot_menu_button") || !is_user_bot(bot_user_id)) {
|
||||
|
@ -12772,6 +12721,15 @@ void ContactsManager::on_update_user_full_greeting_message(UserFull *user_full,
|
|||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_user_commands(
|
||||
UserId user_id, vector<telegram_api::object_ptr<telegram_api::botCommand>> &&bot_commands) {
|
||||
UserFull *user_full = get_user_full_force(user_id, "on_update_user_commands");
|
||||
if (user_full != nullptr) {
|
||||
on_update_user_full_commands(user_full, user_id, std::move(bot_commands));
|
||||
update_user_full(user_full, user_id, "on_update_user_commands");
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_user_full_commands(UserFull *user_full, UserId user_id,
|
||||
vector<tl_object_ptr<telegram_api::botCommand>> &&bot_commands) {
|
||||
CHECK(user_full != nullptr);
|
||||
|
@ -14404,6 +14362,14 @@ void ContactsManager::on_update_channel_photo(Channel *c, ChannelId channel_id,
|
|||
true);
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_chat_bot_commands(ChatId chat_id, BotCommands &&bot_commands) {
|
||||
auto chat_full = get_chat_full_force(chat_id, "on_update_chat_bot_commands");
|
||||
if (chat_full != nullptr && BotCommands::update_all_bot_commands(chat_full->bot_commands, std::move(bot_commands))) {
|
||||
chat_full->is_changed = true;
|
||||
update_chat_full(chat_full, chat_id, "on_update_chat_bot_commands");
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_channel_photo(Channel *c, ChannelId channel_id, DialogPhoto &&photo,
|
||||
bool invalidate_photo_cache) {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
|
@ -16343,6 +16309,15 @@ void ContactsManager::on_update_channel_administrator_count(ChannelId channel_id
|
|||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_channel_bot_commands(ChannelId channel_id, BotCommands &&bot_commands) {
|
||||
auto channel_full = get_channel_full_force(channel_id, true, "on_update_channel_bot_commands");
|
||||
if (channel_full != nullptr &&
|
||||
BotCommands::update_all_bot_commands(channel_full->bot_commands, std::move(bot_commands))) {
|
||||
channel_full->is_changed = true;
|
||||
update_channel_full(channel_full, channel_id, "on_update_channel_bot_commands");
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_get_chat_empty(telegram_api::chatEmpty &chat, const char *source) {
|
||||
ChatId chat_id(chat.id_);
|
||||
if (!chat_id.is_valid()) {
|
||||
|
|
|
@ -258,6 +258,8 @@ class ContactsManager final : public Actor {
|
|||
void on_update_user_greeting_message(UserId user_id, BusinessGreetingMessage &&greeting_message);
|
||||
void on_update_user_need_phone_number_privacy_exception(UserId user_id, bool need_phone_number_privacy_exception);
|
||||
void on_update_user_wallpaper_overridden(UserId user_id, bool wallpaper_overridden);
|
||||
void on_update_user_commands(UserId user_id,
|
||||
vector<telegram_api::object_ptr<telegram_api::botCommand>> &&bot_commands);
|
||||
|
||||
void on_set_profile_photo(UserId user_id, tl_object_ptr<telegram_api::photos_photo> &&photo, bool is_fallback,
|
||||
int64 old_photo_id, Promise<Unit> &&promise);
|
||||
|
@ -273,6 +275,7 @@ class ContactsManager final : public Actor {
|
|||
void on_update_chat_delete_user(ChatId chat_id, UserId user_id, int32 version);
|
||||
void on_update_chat_default_permissions(ChatId chat_id, RestrictedRights default_permissions, int32 version);
|
||||
void on_update_chat_pinned_message(ChatId chat_id, MessageId pinned_message_id, int32 version);
|
||||
void on_update_chat_bot_commands(ChatId chat_id, BotCommands &&bot_commands);
|
||||
|
||||
void on_update_channel_participant_count(ChannelId channel_id, int32 participant_count);
|
||||
void on_update_channel_editable_username(ChannelId channel_id, string &&username);
|
||||
|
@ -297,12 +300,10 @@ class ContactsManager final : public Actor {
|
|||
void on_update_channel_has_pinned_stories(ChannelId channel_id, bool has_pinned_stories);
|
||||
void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions);
|
||||
void on_update_channel_administrator_count(ChannelId channel_id, int32 administrator_count);
|
||||
void on_update_channel_bot_commands(ChannelId channel_id, BotCommands &&bot_commands);
|
||||
|
||||
int32 on_update_peer_located(vector<tl_object_ptr<telegram_api::PeerLocated>> &&peers, bool from_update);
|
||||
|
||||
void on_update_bot_commands(DialogId dialog_id, UserId bot_user_id,
|
||||
vector<tl_object_ptr<telegram_api::botCommand>> &&bot_commands);
|
||||
|
||||
void on_update_bot_menu_button(UserId bot_user_id, tl_object_ptr<telegram_api::BotMenuButton> &&bot_menu_button);
|
||||
|
||||
void speculative_add_channel_participants(ChannelId channel_id, const vector<UserId> &added_user_ids,
|
||||
|
|
|
@ -1790,6 +1790,40 @@ bool DialogManager::is_dialog_removed_from_dialog_list(DialogId dialog_id) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void DialogManager::on_update_dialog_bot_commands(
|
||||
DialogId dialog_id, UserId bot_user_id, vector<telegram_api::object_ptr<telegram_api::botCommand>> &&bot_commands) {
|
||||
if (!bot_user_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive updateBotCommands about invalid " << bot_user_id;
|
||||
return;
|
||||
}
|
||||
if (!td_->contacts_manager_->have_user_force(bot_user_id, "on_update_dialog_bot_commands") ||
|
||||
!td_->contacts_manager_->is_user_bot(bot_user_id)) {
|
||||
return;
|
||||
}
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
if (DialogId(bot_user_id) != dialog_id) {
|
||||
LOG(ERROR) << "Receive commands of " << bot_user_id << " in " << dialog_id;
|
||||
return;
|
||||
}
|
||||
return td_->contacts_manager_->on_update_user_commands(bot_user_id, std::move(bot_commands));
|
||||
case DialogType::Chat:
|
||||
return td_->contacts_manager_->on_update_chat_bot_commands(dialog_id.get_chat_id(),
|
||||
BotCommands(bot_user_id, std::move(bot_commands)));
|
||||
case DialogType::Channel:
|
||||
return td_->contacts_manager_->on_update_channel_bot_commands(dialog_id.get_channel_id(),
|
||||
BotCommands(bot_user_id, std::move(bot_commands)));
|
||||
case DialogType::SecretChat:
|
||||
default:
|
||||
LOG(ERROR) << "Receive updateBotCommands in " << dialog_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DialogManager::on_dialog_usernames_updated(DialogId dialog_id, const Usernames &old_usernames,
|
||||
const Usernames &new_usernames) {
|
||||
LOG(INFO) << "Update usernames in " << dialog_id << " from " << old_usernames << " to " << new_usernames;
|
||||
|
|
|
@ -179,6 +179,9 @@ class DialogManager final : public Actor {
|
|||
void upload_dialog_photo(DialogId dialog_id, FileId file_id, bool is_animation, double main_frame_timestamp,
|
||||
bool is_reupload, Promise<Unit> &&promise, vector<int> bad_parts = {});
|
||||
|
||||
void on_update_dialog_bot_commands(DialogId dialog_id, UserId bot_user_id,
|
||||
vector<telegram_api::object_ptr<telegram_api::botCommand>> &&bot_commands);
|
||||
|
||||
void on_dialog_usernames_updated(DialogId dialog_id, const Usernames &old_usernames, const Usernames &new_usernames);
|
||||
|
||||
void on_dialog_usernames_received(DialogId dialog_id, const Usernames &usernames, bool from_database);
|
||||
|
|
|
@ -3981,8 +3981,8 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerBlocked> up
|
|||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotCommands> update, Promise<Unit> &&promise) {
|
||||
td_->contacts_manager_->on_update_bot_commands(DialogId(update->peer_), UserId(update->bot_id_),
|
||||
std::move(update->commands_));
|
||||
td_->dialog_manager_->on_update_dialog_bot_commands(DialogId(update->peer_), UserId(update->bot_id_),
|
||||
std::move(update->commands_));
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue