Allow to set ignore_sensitive_content_restrictions option.

GitOrigin-RevId: 17899f72c0485c821c150a258232e1348195a936
This commit is contained in:
levlam 2019-12-20 02:58:41 +03:00
parent 6d8a816a68
commit 7a92ee35fc
4 changed files with 73 additions and 1 deletions

View File

@ -951,6 +951,26 @@ void ConfigManager::get_content_settings(Promise<Unit> &&promise) {
}
}
void ConfigManager::set_content_settings(bool ignore_sensitive_content_restrictions, Promise<Unit> &&promise) {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
auto &queries = set_content_settings_queries_[ignore_sensitive_content_restrictions];
queries.push_back(std::move(promise));
if (!is_set_content_settings_request_sent_) {
is_set_content_settings_request_sent_ = true;
int32 flags = 0;
if (ignore_sensitive_content_restrictions) {
flags |= telegram_api::account_setContentSettings::SENSITIVE_ENABLED_MASK;
}
G()->net_query_dispatcher().dispatch_with_callback(
G()->net_query_creator().create(
create_storer(telegram_api::account_setContentSettings(flags, false /*ignored*/))),
actor_shared(this, 3 + static_cast<uint64>(ignore_sensitive_content_restrictions)));
}
}
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));
@ -972,6 +992,34 @@ void ConfigManager::request_config_from_dc_impl(DcId dc_id) {
void ConfigManager::on_result(NetQueryPtr res) {
auto token = get_link_token();
if (token == 3 || token == 4) {
is_set_content_settings_request_sent_ = false;
bool ignore_sensitive_content_restrictions = (token == 4);
auto promises = std::move(set_content_settings_queries_[ignore_sensitive_content_restrictions]);
set_content_settings_queries_[ignore_sensitive_content_restrictions].clear();
CHECK(!promises.empty());
auto result_ptr = fetch_result<telegram_api::account_setContentSettings>(std::move(res));
if (result_ptr.is_error()) {
for (auto &promise : promises) {
promise.set_error(result_ptr.error().clone());
}
} else {
ConfigShared &shared_config = G()->shared_config();
if (shared_config.get_option_boolean("can_ignore_sensitive_content_restrictions")) {
shared_config.set_option_boolean("ignore_sensitive_content_restrictions",
ignore_sensitive_content_restrictions);
}
for (auto &promise : promises) {
promise.set_value(Unit());
}
}
if (!set_content_settings_queries_[!ignore_sensitive_content_restrictions].empty()) {
set_content_settings(!ignore_sensitive_content_restrictions, Auto());
}
return;
}
if (token == 2) {
auto promises = std::move(get_content_settings_queries_);
get_content_settings_queries_.clear();

View File

@ -87,6 +87,8 @@ class ConfigManager : public NetQueryCallback {
void get_content_settings(Promise<Unit> &&promise);
void set_content_settings(bool ignore_sensitive_content_restrictions, Promise<Unit> &&promise);
void on_dc_options_update(DcOptions dc_options);
private:
@ -98,6 +100,8 @@ class ConfigManager : public NetQueryCallback {
vector<Promise<td_api::object_ptr<td_api::JsonValue>>> get_app_config_queries_;
vector<Promise<Unit>> get_content_settings_queries_;
vector<Promise<Unit>> set_content_settings_queries_[2];
bool is_set_content_settings_request_sent_ = false;
void start_up() override;
void hangup_shared() override;

View File

@ -41,7 +41,6 @@ class ConfigShared {
void set_option_string(Slice name, Slice value);
bool have_option(Slice name) const;
string get_option(Slice name) const;
std::unordered_map<string, string> get_options(Slice prefix) const;
std::unordered_map<string, string> get_options() const;
@ -59,6 +58,8 @@ class ConfigShared {
bool set_option(Slice name, Slice value);
string get_option(Slice name) const;
void on_option_updated(Slice name) const;
};

View File

@ -7085,6 +7085,25 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
if (false && !is_bot && set_boolean_option("include_sponsored_chat_to_unread_count")) {
return;
}
if (!is_bot && request.name_ == "ignore_sensitive_content_restrictions") {
if (!G()->shared_config().get_option_boolean("can_ignore_sensitive_content_restrictions")) {
return send_error_raw(id, 3, "Option \"ignore_sensitive_content_restrictions\" can't be changed by the user");
}
if (value_constructor_id != td_api::optionValueBoolean::ID &&
value_constructor_id != td_api::optionValueEmpty::ID) {
return send_error_raw(id, 3, "Option \"ignore_sensitive_content_restrictions\" must have boolean value");
}
auto ignore_sensitive_content_restrictions =
value_constructor_id == td_api::optionValueBoolean::ID &&
static_cast<td_api::optionValueBoolean *>(request.value_.get())->value_;
CREATE_OK_REQUEST_PROMISE();
send_closure_later(config_manager_, &ConfigManager::set_content_settings, ignore_sensitive_content_restrictions,
std::move(promise));
return;
}
break;
case 'l':
if (!is_bot && set_string_option("language_pack_database_path", [](Slice value) { return true; })) {