Add ignore_sensitive_content_restrictions and can_ignore_sensitive_content_restrictions options.
GitOrigin-RevId: 9a46d3eae3b8e17b51cf33b02e14aedc84261800
This commit is contained in:
parent
57911db0ba
commit
6d8a816a68
@ -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<td_api::object_ptr<td_api::JsonValue>> &&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<td_api::object_ptr<td_api::JsonValue>
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigManager::get_content_settings(Promise<Unit> &&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<telegram_api::account_getContentSettings>(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<telegram_api::config> 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<telegram_api::JSONValue> &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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,8 @@ class ConfigManager : public NetQueryCallback {
|
||||
|
||||
void get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise);
|
||||
|
||||
void get_content_settings(Promise<Unit> &&promise);
|
||||
|
||||
void on_dc_options_update(DcOptions dc_options);
|
||||
|
||||
private:
|
||||
@ -95,6 +97,7 @@ class ConfigManager : public NetQueryCallback {
|
||||
Timestamp expire_time_;
|
||||
|
||||
vector<Promise<td_api::object_ptr<td_api::JsonValue>>> get_app_config_queries_;
|
||||
vector<Promise<Unit>> get_content_settings_queries_;
|
||||
|
||||
void start_up() override;
|
||||
void hangup_shared() override;
|
||||
|
@ -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<Unit> &&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<Unit> &&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<Unit> &&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;
|
||||
|
Loading…
Reference in New Issue
Block a user