Send updateChatIsTranslatable when premium is switched on or off.

This commit is contained in:
levlam 2023-01-20 12:57:06 +03:00
parent 337aef5c02
commit 8137572794
3 changed files with 17 additions and 1 deletions

View File

@ -11316,6 +11316,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
td_->option_manager_->set_option_boolean("is_premium", u->is_premium);
send_closure(td_->config_manager_, &ConfigManager::request_config, true);
td_->stickers_manager_->reload_top_reactions();
td_->messages_manager_->update_is_translatable(u->is_premium);
}
}
if (u->is_name_changed || u->is_username_changed || u->is_is_contact_changed) {

View File

@ -20952,7 +20952,7 @@ Status MessagesManager::toggle_dialog_is_translatable(DialogId dialog_id, bool i
return Status::Error(400, "Can't access the chat");
}
if (!td_->option_manager_->get_option_boolean("is_premium")) {
return Status::Error(400, "The method is available for Telegram Premium users only");
return Status::Error(400, "The method is available to Telegram Premium users only");
}
if (is_translatable == d->is_translatable) {
@ -32989,6 +32989,19 @@ void MessagesManager::on_update_dialog_is_translatable(DialogId dialog_id, bool
set_dialog_is_translatable(d, is_translatable);
}
void MessagesManager::update_is_translatable(bool new_is_premium) {
if (td_->auth_manager_->is_bot()) {
return;
}
dialogs_.foreach([&](const DialogId &dialog_id, const unique_ptr<Dialog> &dialog) {
if (dialog->is_translatable) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateChatIsTranslatable>(dialog_id.get(), new_is_premium));
}
});
}
void MessagesManager::set_dialog_is_translatable(Dialog *d, bool is_translatable) {
if (td_->auth_manager_->is_bot()) {
// just in case

View File

@ -289,6 +289,8 @@ class MessagesManager final : public Actor {
void on_update_dialog_is_translatable(DialogId dialog_id, bool is_translatable);
void update_is_translatable(bool new_is_premium);
void on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked);
void on_update_dialog_last_pinned_message_id(DialogId dialog_id, MessageId last_pinned_message_id);