Improve handling of internal options with updates.
This commit is contained in:
parent
02a4851e12
commit
754ff0fc53
@ -943,13 +943,11 @@ void send_set_default_reaction_query(Td *td) {
|
||||
td->create_handler<SetDefaultReactionQuery>()->send(td->option_manager_->get_option_string("default_reaction"));
|
||||
}
|
||||
|
||||
void send_update_default_reaction_type(const string &default_reaction) {
|
||||
td_api::object_ptr<td_api::updateDefaultReactionType> get_update_default_reaction_type(const string &default_reaction) {
|
||||
if (default_reaction.empty()) {
|
||||
LOG(ERROR) << "Have no default reaction";
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateDefaultReactionType>(get_reaction_type_object(default_reaction)));
|
||||
return td_api::make_object<td_api::updateDefaultReactionType>(get_reaction_type_object(default_reaction));
|
||||
}
|
||||
|
||||
void report_message_reactions(Td *td, FullMessageId full_message_id, DialogId chooser_dialog_id,
|
||||
|
@ -224,7 +224,7 @@ void set_default_reaction(Td *td, string reaction, Promise<Unit> &&promise);
|
||||
|
||||
void send_set_default_reaction_query(Td *td);
|
||||
|
||||
void send_update_default_reaction_type(const string &default_reaction);
|
||||
td_api::object_ptr<td_api::updateDefaultReactionType> get_update_default_reaction_type(const string &default_reaction);
|
||||
|
||||
void report_message_reactions(Td *td, FullMessageId full_message_id, DialogId chooser_dialog_id,
|
||||
Promise<Unit> &&promise);
|
||||
|
@ -62,19 +62,10 @@ OptionManager::OptionManager(Td *td)
|
||||
if (!is_internal_option(name)) {
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateOption>(name, get_option_value_object(name_value.second)));
|
||||
} else if (name == "otherwise_relogin_days") {
|
||||
auto days = narrow_cast<int32>(get_option_integer(name));
|
||||
if (days > 0) {
|
||||
vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
|
||||
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object(added_actions, {}));
|
||||
}
|
||||
} else if (name == "default_reaction") {
|
||||
auto value = get_option_string(name);
|
||||
if (value.empty()) {
|
||||
// legacy
|
||||
set_option_empty(name);
|
||||
} else {
|
||||
send_update_default_reaction_type(value);
|
||||
} else {
|
||||
auto update = get_internal_option_update(name);
|
||||
if (update != nullptr) {
|
||||
send_closure(G()->td(), &Td::send_update, std::move(update));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,6 +207,11 @@ void OptionManager::set_option(Slice name, Slice value) {
|
||||
if (!is_internal_option(name)) {
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateOption>(name.str(), get_option_value_object(get_option(name))));
|
||||
} else {
|
||||
auto update = get_internal_option_update(name);
|
||||
if (update != nullptr) {
|
||||
send_closure(G()->td(), &Td::send_update, std::move(update));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,6 +295,20 @@ bool OptionManager::is_internal_option(Slice name) {
|
||||
}
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::Update> OptionManager::get_internal_option_update(Slice name) const {
|
||||
if (name == "default_reaction") {
|
||||
return get_update_default_reaction_type(get_option_string(name));
|
||||
}
|
||||
if (name == "otherwise_relogin_days") {
|
||||
auto days = narrow_cast<int32>(get_option_integer(name));
|
||||
if (days > 0) {
|
||||
vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
|
||||
return get_update_suggested_actions_object(added_actions, {});
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const vector<Slice> &OptionManager::get_synchronous_options() {
|
||||
static const vector<Slice> options{"version", "commit_hash"};
|
||||
return options;
|
||||
@ -334,9 +344,6 @@ void OptionManager::on_option_updated(Slice name) {
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (name == "default_reaction") {
|
||||
send_update_default_reaction_type(get_option_string(name));
|
||||
}
|
||||
if (name == "dice_emojis") {
|
||||
send_closure(td_->stickers_manager_actor_, &StickersManager::on_update_dice_emojis);
|
||||
}
|
||||
@ -414,13 +421,6 @@ void OptionManager::on_option_updated(Slice name) {
|
||||
if (name == "online_cloud_timeout_ms") {
|
||||
send_closure(td_->notification_manager_actor_, &NotificationManager::on_online_cloud_timeout_changed);
|
||||
}
|
||||
if (name == "otherwise_relogin_days") {
|
||||
auto days = narrow_cast<int32>(get_option_integer(name));
|
||||
if (days > 0) {
|
||||
vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
|
||||
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object(added_actions, {}));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (name == "rating_e_decay") {
|
||||
@ -867,6 +867,11 @@ void OptionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>>
|
||||
if (!is_internal_option(option.first)) {
|
||||
updates.push_back(
|
||||
td_api::make_object<td_api::updateOption>(option.first, get_option_value_object(option.second)));
|
||||
} else {
|
||||
auto update = get_internal_option_update(option.first);
|
||||
if (update != nullptr) {
|
||||
updates.push_back(std::move(update));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,8 @@ class OptionManager {
|
||||
|
||||
static bool is_internal_option(Slice name);
|
||||
|
||||
td_api::object_ptr<td_api::Update> get_internal_option_update(Slice name) const;
|
||||
|
||||
static const vector<Slice> &get_synchronous_options();
|
||||
|
||||
static td_api::object_ptr<td_api::OptionValue> get_unix_time_option_value_object();
|
||||
|
Loading…
x
Reference in New Issue
Block a user