From 6d8a816a6873271bde6b0f7e4946d5c79bdd8fb7 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 19 Dec 2019 23:00:28 +0300 Subject: [PATCH] Add ignore_sensitive_content_restrictions and can_ignore_sensitive_content_restrictions options. GitOrigin-RevId: 9a46d3eae3b8e17b51cf33b02e14aedc84261800 --- td/telegram/ConfigManager.cpp | 63 +++++++++++++++++++++++++++++++++++ td/telegram/ConfigManager.h | 3 ++ td/telegram/Td.cpp | 26 +++++++++++++-- 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 651da6569..db619b738 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/ConfigManager.h" +#include "td/telegram/AuthManager.h" #include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/JsonValue.h" @@ -20,6 +21,7 @@ #include "td/telegram/net/PublicRsaKeyShared.h" #include "td/telegram/net/Session.h" #include "td/telegram/StateManager.h" +#include "td/telegram/Td.h" #include "td/telegram/TdDb.h" #include "td/telegram/telegram_api.h" @@ -906,6 +908,10 @@ void ConfigManager::try_stop() { } void ConfigManager::request_config() { + if (G()->close_flag()) { + return; + } + if (config_sent_cnt_ != 0) { return; } @@ -913,6 +919,10 @@ void ConfigManager::request_config() { } void ConfigManager::get_app_config(Promise> &&promise) { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } + get_app_config_queries_.push_back(std::move(promise)); if (get_app_config_queries_.size() == 1) { G()->net_query_dispatcher().dispatch_with_callback( @@ -923,6 +933,24 @@ void ConfigManager::get_app_config(Promise } } +void ConfigManager::get_content_settings(Promise &&promise) { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } + + auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get(); + if (!auth_manager->is_authorized() || auth_manager->is_bot()) { + return promise.set_value(Unit()); + } + + get_content_settings_queries_.push_back(std::move(promise)); + if (get_content_settings_queries_.size() == 1) { + G()->net_query_dispatcher().dispatch_with_callback( + G()->net_query_creator().create(create_storer(telegram_api::account_getContentSettings())), + actor_shared(this, 2)); + } +} + void ConfigManager::on_dc_options_update(DcOptions dc_options) { save_dc_options_update(dc_options); send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, std::move(dc_options)); @@ -944,6 +972,28 @@ void ConfigManager::request_config_from_dc_impl(DcId dc_id) { void ConfigManager::on_result(NetQueryPtr res) { auto token = get_link_token(); + if (token == 2) { + auto promises = std::move(get_content_settings_queries_); + get_content_settings_queries_.clear(); + CHECK(!promises.empty()); + auto result_ptr = fetch_result(std::move(res)); + if (result_ptr.is_error()) { + for (auto &promise : promises) { + promise.set_error(result_ptr.error().clone()); + } + return; + } + + auto result = result_ptr.move_as_ok(); + ConfigShared &shared_config = G()->shared_config(); + shared_config.set_option_boolean("ignore_sensitive_content_restrictions", result->sensitive_enabled_); + shared_config.set_option_boolean("can_ignore_sensitive_content_restrictions", result->sensitive_can_change_); + + for (auto &promise : promises) { + promise.set_value(Unit()); + } + return; + } if (token == 1) { auto promises = std::move(get_app_config_queries_); get_app_config_queries_.clear(); @@ -957,6 +1007,7 @@ void ConfigManager::on_result(NetQueryPtr res) { promise.set_error(result_ptr.error().clone()); } } + return; } auto result = result_ptr.move_as_ok(); @@ -1160,6 +1211,10 @@ void ConfigManager::process_config(tl_object_ptr config) { if (is_from_main_dc) { get_app_config(Auto()); + if (!shared_config.have_option("can_ignore_sensitive_content_restrictions") || + !shared_config.have_option("ignore_sensitive_content_restrictions")) { + get_content_settings(Auto()); + } } } @@ -1235,8 +1290,16 @@ void ConfigManager::process_app_config(tl_object_ptr &c } if (ignored_restriction_reasons.empty()) { shared_config.set_option_empty("ignored_restriction_reasons"); + + if (shared_config.get_option_boolean("ignore_sensitive_content_restrictions", true)) { + get_content_settings(Auto()); + } } else { shared_config.set_option_string("ignored_restriction_reasons", ignored_restriction_reasons); + + if (!shared_config.get_option_boolean("can_ignore_sensitive_content_restrictions")) { + get_content_settings(Auto()); + } } } diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 32b79fe09..015456202 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -85,6 +85,8 @@ class ConfigManager : public NetQueryCallback { void get_app_config(Promise> &&promise); + void get_content_settings(Promise &&promise); + void on_dc_options_update(DcOptions dc_options); private: @@ -95,6 +97,7 @@ class ConfigManager : public NetQueryCallback { Timestamp expire_time_; vector>> get_app_config_queries_; + vector> get_content_settings_queries_; void start_up() override; void hangup_shared() override; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 6975ee734..d4175d884 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6906,6 +6906,17 @@ void Td::on_request(uint64 id, td_api::getOption &request) { bool is_bot = auth_manager_ != nullptr && auth_manager_->is_authorized() && auth_manager_->is_bot(); switch (request.name_[0]) { // all these options should be added to getCurrentState + case 'c': + if (!is_bot && request.name_ == "can_ignore_sensitive_content_restrictions") { + auto promise = PromiseCreator::lambda([actor_id = actor_id(this), id](Result &&result) { + // the option is already updated on success, ignore errors + send_closure(actor_id, &Td::send_result, id, + G()->shared_config().get_option_value("can_ignore_sensitive_content_restrictions")); + }); + send_closure_later(config_manager_, &ConfigManager::get_content_settings, std::move(promise)); + return; + } + break; case 'd': if (!is_bot && request.name_ == "disable_contact_registered_notifications") { auto promise = PromiseCreator::lambda([actor_id = actor_id(this), id](Result &&result) { @@ -6913,8 +6924,19 @@ void Td::on_request(uint64 id, td_api::getOption &request) { send_closure(actor_id, &Td::send_result, id, G()->shared_config().get_option_value("disable_contact_registered_notifications")); }); - send_closure(notification_manager_actor_, &NotificationManager::get_disable_contact_registered_notifications, - std::move(promise)); + send_closure_later(notification_manager_actor_, + &NotificationManager::get_disable_contact_registered_notifications, std::move(promise)); + return; + } + break; + case 'i': + if (!is_bot && request.name_ == "ignore_sensitive_content_restrictions") { + auto promise = PromiseCreator::lambda([actor_id = actor_id(this), id](Result &&result) { + // the option is already updated on success, ignore errors + send_closure(actor_id, &Td::send_result, id, + G()->shared_config().get_option_value("ignore_sensitive_content_restrictions")); + }); + send_closure_later(config_manager_, &ConfigManager::get_content_settings, std::move(promise)); return; } break;