2021-12-15 23:09:59 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2021-12-15 23:09:59 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/OptionManager.h"
|
|
|
|
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/AnimationsManager.h"
|
2022-03-30 13:48:23 +02:00
|
|
|
#include "td/telegram/AttachMenuManager.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/AuthManager.h"
|
2021-12-16 10:07:32 +01:00
|
|
|
#include "td/telegram/ConfigManager.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/ContactsManager.h"
|
2021-12-16 14:16:34 +01:00
|
|
|
#include "td/telegram/DialogId.h"
|
2022-07-11 13:01:56 +02:00
|
|
|
#include "td/telegram/GitCommitHash.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/Global.h"
|
2021-12-16 11:13:14 +01:00
|
|
|
#include "td/telegram/JsonValue.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/LanguagePackManager.h"
|
2022-08-15 21:47:02 +02:00
|
|
|
#include "td/telegram/MessageReaction.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/net/MtprotoHeader.h"
|
|
|
|
#include "td/telegram/net/NetQueryDispatcher.h"
|
|
|
|
#include "td/telegram/NotificationManager.h"
|
2021-12-16 11:13:14 +01:00
|
|
|
#include "td/telegram/StateManager.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/StickersManager.h"
|
|
|
|
#include "td/telegram/StorageManager.h"
|
|
|
|
#include "td/telegram/SuggestedAction.h"
|
|
|
|
#include "td/telegram/Td.h"
|
2021-12-16 11:13:14 +01:00
|
|
|
#include "td/telegram/TdDb.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/TopDialogManager.h"
|
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
#include "td/db/KeyValueSyncInterface.h"
|
|
|
|
#include "td/db/TsSeqKeyValue.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2022-07-11 14:36:29 +02:00
|
|
|
#include "td/utils/algorithm.h"
|
2022-08-18 13:54:57 +02:00
|
|
|
#include "td/utils/logging.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/utils/misc.h"
|
2022-06-02 15:19:16 +02:00
|
|
|
#include "td/utils/port/Clocks.h"
|
2021-12-16 11:13:14 +01:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2021-12-16 14:16:34 +01:00
|
|
|
#include "td/utils/Status.h"
|
2021-12-16 11:13:14 +01:00
|
|
|
|
2021-12-16 13:18:51 +01:00
|
|
|
#include <cmath>
|
2022-05-14 19:09:08 +02:00
|
|
|
#include <functional>
|
2021-12-16 11:13:14 +01:00
|
|
|
#include <limits>
|
2021-12-15 23:45:43 +01:00
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
namespace td {
|
|
|
|
|
2022-08-18 17:52:59 +02:00
|
|
|
OptionManager::OptionManager(Td *td)
|
|
|
|
: td_(td), options_(td::make_unique<TsSeqKeyValue>()), option_pmc_(G()->td_db()->get_config_pmc_shared()) {
|
2021-12-16 13:18:51 +01:00
|
|
|
send_unix_time_update();
|
2022-04-12 17:33:46 +02:00
|
|
|
|
2022-08-18 14:59:32 +02:00
|
|
|
auto all_options = option_pmc_->get_all();
|
|
|
|
all_options["utc_time_offset"] = PSTRING() << 'I' << Clocks::tz_offset();
|
|
|
|
for (const auto &name_value : all_options) {
|
2022-08-18 13:54:57 +02:00
|
|
|
const string &name = name_value.first;
|
2022-08-22 20:29:09 +02:00
|
|
|
options_->set(name, name_value.second);
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!is_internal_option(name)) {
|
2022-08-18 14:59:32 +02:00
|
|
|
send_closure(G()->td(), &Td::send_update,
|
2022-08-22 20:29:09 +02:00
|
|
|
td_api::make_object<td_api::updateOption>(name, get_option_value_object(name_value.second)));
|
2022-08-18 13:54:57 +02:00
|
|
|
} 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, {}));
|
|
|
|
}
|
2022-08-22 14:23:17 +02:00
|
|
|
} else if (name == "default_reaction") {
|
2022-08-22 20:29:09 +02:00
|
|
|
send_update_default_reaction_type(get_option_string(name));
|
2022-08-18 13:54:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_option("message_text_length_max")) {
|
|
|
|
set_option_integer("message_text_length_max", 4096);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("message_caption_length_max")) {
|
|
|
|
set_option_integer("message_caption_length_max", 1024);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("bio_length_max")) {
|
|
|
|
set_option_integer("bio_length_max", 70);
|
2022-05-30 02:23:21 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("suggested_video_note_length")) {
|
|
|
|
set_option_integer("suggested_video_note_length", 384);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("suggested_video_note_video_bitrate")) {
|
|
|
|
set_option_integer("suggested_video_note_video_bitrate", 1000);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("suggested_video_note_audio_bitrate")) {
|
|
|
|
set_option_integer("suggested_video_note_audio_bitrate", 64);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("notification_sound_duration_max")) {
|
|
|
|
set_option_integer("notification_sound_duration_max", 5);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("notification_sound_size_max")) {
|
|
|
|
set_option_integer("notification_sound_size_max", 307200);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("notification_sound_count_max")) {
|
|
|
|
set_option_integer("notification_sound_count_max", G()->is_test_dc() ? 5 : 100);
|
2022-04-12 17:33:46 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("chat_filter_count_max")) {
|
|
|
|
set_option_integer("chat_filter_count_max", G()->is_test_dc() ? 3 : 10);
|
2022-05-23 17:26:54 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!have_option("chat_filter_chosen_chat_count_max")) {
|
|
|
|
set_option_integer("chat_filter_chosen_chat_count_max", G()->is_test_dc() ? 5 : 100);
|
2022-05-23 19:04:36 +02:00
|
|
|
}
|
2022-09-07 09:25:21 +02:00
|
|
|
if (!have_option("themed_emoji_statuses_sticker_set_id")) {
|
2022-08-31 18:03:26 +02:00
|
|
|
auto sticker_set_id =
|
|
|
|
G()->is_test_dc() ? static_cast<int64>(2964141614563343) : static_cast<int64>(773947703670341676);
|
2022-09-07 09:25:21 +02:00
|
|
|
set_option_integer("themed_emoji_statuses_sticker_set_id", sticker_set_id);
|
2022-08-31 18:03:26 +02:00
|
|
|
}
|
2021-12-15 23:09:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OptionManager::~OptionManager() = default;
|
|
|
|
|
2022-08-18 18:12:15 +02:00
|
|
|
void OptionManager::on_td_inited() {
|
|
|
|
is_td_inited_ = true;
|
2022-08-18 18:38:30 +02:00
|
|
|
|
2022-08-18 18:54:04 +02:00
|
|
|
for (auto &request : pending_get_options_) {
|
|
|
|
get_option(request.first, std::move(request.second));
|
|
|
|
}
|
|
|
|
reset_to_empty(pending_get_options_);
|
2022-08-18 18:12:15 +02:00
|
|
|
}
|
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
void OptionManager::set_option_boolean(Slice name, bool value) {
|
|
|
|
set_option(name, value ? Slice("Btrue") : Slice("Bfalse"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionManager::set_option_empty(Slice name) {
|
|
|
|
set_option(name, Slice());
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionManager::set_option_integer(Slice name, int64 value) {
|
|
|
|
set_option(name, PSLICE() << 'I' << value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionManager::set_option_string(Slice name, Slice value) {
|
|
|
|
set_option(name, PSLICE() << 'S' << value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OptionManager::have_option(Slice name) const {
|
|
|
|
return options_->isset(name.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OptionManager::get_option_boolean(Slice name, bool default_value) const {
|
|
|
|
auto value = get_option(name);
|
|
|
|
if (value.empty()) {
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
if (value == "Btrue") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (value == "Bfalse") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "Found \"" << value << "\" instead of boolean option " << name;
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 OptionManager::get_option_integer(Slice name, int64 default_value) const {
|
|
|
|
auto value = get_option(name);
|
|
|
|
if (value.empty()) {
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
if (value[0] != 'I') {
|
|
|
|
LOG(ERROR) << "Found \"" << value << "\" instead of integer option " << name;
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
return to_integer<int64>(value.substr(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
string OptionManager::get_option_string(Slice name, string default_value) const {
|
|
|
|
auto value = get_option(name);
|
|
|
|
if (value.empty()) {
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
if (value[0] != 'S') {
|
|
|
|
LOG(ERROR) << "Found \"" << value << "\" instead of string option " << name;
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
return value.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionManager::set_option(Slice name, Slice value) {
|
|
|
|
CHECK(!name.empty());
|
|
|
|
CHECK(Scheduler::instance()->sched_id() == 0);
|
|
|
|
if (value.empty()) {
|
|
|
|
if (option_pmc_->erase(name.str()) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
option_pmc_->erase(name.str());
|
|
|
|
} else {
|
|
|
|
if (options_->set(name, value) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
option_pmc_->set(name.str(), value.str());
|
|
|
|
}
|
2022-08-18 18:12:15 +02:00
|
|
|
|
|
|
|
if (!G()->close_flag() && is_td_inited_) {
|
|
|
|
on_option_updated(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
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))));
|
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
string OptionManager::get_option(Slice name) const {
|
|
|
|
return options_->get(name.str());
|
|
|
|
}
|
|
|
|
|
2021-12-16 13:18:51 +01:00
|
|
|
td_api::object_ptr<td_api::OptionValue> OptionManager::get_unix_time_option_value_object() {
|
|
|
|
return td_api::make_object<td_api::optionValueInteger>(G()->unix_time());
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionManager::send_unix_time_update() {
|
|
|
|
last_sent_server_time_difference_ = G()->get_server_time_difference();
|
|
|
|
td_->send_update(td_api::make_object<td_api::updateOption>("unix_time", get_unix_time_option_value_object()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionManager::on_update_server_time_difference() {
|
2022-08-18 17:52:59 +02:00
|
|
|
// can be called from any thread
|
2021-12-16 13:18:51 +01:00
|
|
|
if (std::abs(G()->get_server_time_difference() - last_sent_server_time_difference_) < 0.5) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_unix_time_update();
|
|
|
|
}
|
|
|
|
|
2021-12-15 23:45:43 +01:00
|
|
|
void OptionManager::clear_options() {
|
2022-08-18 13:54:57 +02:00
|
|
|
for (const auto &option : options_->get_all()) {
|
2021-12-15 23:45:43 +01:00
|
|
|
if (!is_internal_option(option.first)) {
|
|
|
|
send_closure(
|
|
|
|
G()->td(), &Td::send_update,
|
|
|
|
td_api::make_object<td_api::updateOption>(option.first, td_api::make_object<td_api::optionValueEmpty>()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OptionManager::is_internal_option(Slice name) {
|
|
|
|
switch (name[0]) {
|
|
|
|
case 'a':
|
2022-05-30 01:20:12 +02:00
|
|
|
return name == "about_length_limit_default" || name == "about_length_limit_premium" ||
|
2022-08-17 19:01:03 +02:00
|
|
|
name == "animated_emoji_zoom" || name == "animation_search_emojis" || name == "animation_search_provider";
|
2021-12-15 23:45:43 +01:00
|
|
|
case 'b':
|
|
|
|
return name == "base_language_pack_version";
|
|
|
|
case 'c':
|
2022-01-25 20:53:51 +01:00
|
|
|
return name == "call_receive_timeout_ms" || name == "call_ring_timeout_ms" ||
|
2022-05-23 16:47:06 +02:00
|
|
|
name == "caption_length_limit_default" || name == "caption_length_limit_premium" ||
|
|
|
|
name == "channels_limit_default" || name == "channels_limit_premium" ||
|
|
|
|
name == "channels_public_limit_default" || name == "channels_public_limit_premium" ||
|
2021-12-15 23:45:43 +01:00
|
|
|
name == "channels_read_media_period" || name == "chat_read_mark_expire_period" ||
|
|
|
|
name == "chat_read_mark_size_threshold";
|
|
|
|
case 'd':
|
2022-08-16 22:08:36 +02:00
|
|
|
return name == "dc_txt_domain_name" || name == "default_reaction" || name == "default_reaction_needs_sync" ||
|
2022-05-23 16:47:06 +02:00
|
|
|
name == "dialog_filters_chats_limit_default" || name == "dialog_filters_chats_limit_premium" ||
|
|
|
|
name == "dialog_filters_limit_default" || name == "dialog_filters_limit_premium" ||
|
|
|
|
name == "dialogs_folder_pinned_limit_default" || name == "dialogs_folder_pinned_limit_premium" ||
|
|
|
|
name == "dialogs_pinned_limit_default" || name == "dialogs_pinned_limit_premium" ||
|
|
|
|
name == "dice_emojis" || name == "dice_success_values";
|
2021-12-15 23:45:43 +01:00
|
|
|
case 'e':
|
|
|
|
return name == "edit_time_limit" || name == "emoji_sounds";
|
|
|
|
case 'i':
|
|
|
|
return name == "ignored_restriction_reasons";
|
|
|
|
case 'l':
|
|
|
|
return name == "language_pack_version";
|
|
|
|
case 'm':
|
|
|
|
return name == "my_phone_number";
|
|
|
|
case 'n':
|
|
|
|
return name == "notification_cloud_delay_ms" || name == "notification_default_delay_ms";
|
|
|
|
case 'o':
|
2022-01-25 20:53:51 +01:00
|
|
|
return name == "online_cloud_timeout_ms" || name == "online_update_period_ms" || name == "otherwise_relogin_days";
|
2022-05-23 14:56:31 +02:00
|
|
|
case 'p':
|
2022-05-24 15:14:25 +02:00
|
|
|
return name == "premium_bot_username" || name == "premium_features" || name == "premium_invoice_slug";
|
2021-12-15 23:45:43 +01:00
|
|
|
case 'r':
|
2022-01-25 20:53:51 +01:00
|
|
|
return name == "rating_e_decay" || name == "reactions_uniq_max" || name == "recent_stickers_limit" ||
|
|
|
|
name == "revoke_pm_inbox" || name == "revoke_time_limit" || name == "revoke_pm_time_limit";
|
2021-12-15 23:45:43 +01:00
|
|
|
case 's':
|
2022-05-23 16:47:06 +02:00
|
|
|
return name == "saved_animations_limit" || name == "saved_gifs_limit_default" ||
|
|
|
|
name == "saved_gifs_limit_premium" || name == "session_count" || name == "stickers_faved_limit_default" ||
|
2022-06-10 12:04:46 +02:00
|
|
|
name == "stickers_faved_limit_premium" || name == "stickers_normal_by_emoji_per_premium_num" ||
|
|
|
|
name == "stickers_premium_by_emoji_num";
|
2021-12-15 23:45:43 +01:00
|
|
|
case 'v':
|
|
|
|
return name == "video_note_size_max";
|
|
|
|
case 'w':
|
|
|
|
return name == "webfile_dc_id";
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 14:36:29 +02:00
|
|
|
const vector<Slice> &OptionManager::get_synchronous_options() {
|
|
|
|
static const vector<Slice> options{"version", "commit_hash"};
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:33:56 +02:00
|
|
|
bool OptionManager::is_synchronous_option(Slice name) {
|
2022-07-11 14:36:29 +02:00
|
|
|
return td::contains(get_synchronous_options(), name);
|
2022-07-11 12:33:56 +02:00
|
|
|
}
|
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
void OptionManager::on_option_updated(Slice name) {
|
2021-12-15 23:45:43 +01:00
|
|
|
switch (name[0]) {
|
|
|
|
case 'a':
|
|
|
|
if (name == "animated_emoji_zoom") {
|
|
|
|
// nothing to do: animated emoji zoom is updated only at launch
|
|
|
|
}
|
|
|
|
if (name == "animation_search_emojis") {
|
2022-08-17 21:16:16 +02:00
|
|
|
td_->animations_manager_->on_update_animation_search_emojis();
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
if (name == "animation_search_provider") {
|
2022-08-17 21:16:16 +02:00
|
|
|
td_->animations_manager_->on_update_animation_search_provider();
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
if (name == "base_language_pack_version") {
|
|
|
|
send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_pack_version_changed, true, -1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (name == "connection_parameters") {
|
2022-08-18 13:54:57 +02:00
|
|
|
if (G()->mtproto_header().set_parameters(get_option_string(name))) {
|
2021-12-15 23:45:43 +01:00
|
|
|
G()->net_query_dispatcher().update_mtproto_header();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2022-08-22 14:23:17 +02:00
|
|
|
if (name == "default_reaction") {
|
2022-08-22 20:29:09 +02:00
|
|
|
send_update_default_reaction_type(get_option_string(name));
|
2022-08-22 14:23:17 +02:00
|
|
|
}
|
2021-12-15 23:45:43 +01:00
|
|
|
if (name == "dice_emojis") {
|
|
|
|
send_closure(td_->stickers_manager_actor_, &StickersManager::on_update_dice_emojis);
|
|
|
|
}
|
|
|
|
if (name == "dice_success_values") {
|
|
|
|
send_closure(td_->stickers_manager_actor_, &StickersManager::on_update_dice_success_values);
|
|
|
|
}
|
|
|
|
if (name == "disable_animated_emoji") {
|
|
|
|
td_->stickers_manager_->on_update_disable_animated_emojis();
|
|
|
|
}
|
|
|
|
if (name == "disable_contact_registered_notifications") {
|
|
|
|
send_closure(td_->notification_manager_actor_,
|
|
|
|
&NotificationManager::on_disable_contact_registered_notifications_changed);
|
|
|
|
}
|
|
|
|
if (name == "disable_top_chats") {
|
2022-08-18 13:54:57 +02:00
|
|
|
send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_is_enabled, !get_option_boolean(name));
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (name == "emoji_sounds") {
|
|
|
|
send_closure(td_->stickers_manager_actor_, &StickersManager::on_update_emoji_sounds);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
if (name == "favorite_stickers_limit") {
|
2022-08-17 20:40:03 +02:00
|
|
|
td_->stickers_manager_->on_update_favorite_stickers_limit();
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
if (name == "ignored_restriction_reasons") {
|
|
|
|
send_closure(td_->contacts_manager_actor_, &ContactsManager::on_ignored_restriction_reasons_changed);
|
|
|
|
}
|
|
|
|
if (name == "is_emulator") {
|
2022-08-18 13:54:57 +02:00
|
|
|
if (G()->mtproto_header().set_is_emulator(get_option_boolean(name))) {
|
2021-12-15 23:45:43 +01:00
|
|
|
G()->net_query_dispatcher().update_mtproto_header();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (name == "language_pack_id") {
|
|
|
|
send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_code_changed);
|
2022-08-18 13:54:57 +02:00
|
|
|
if (G()->mtproto_header().set_language_code(get_option_string(name))) {
|
2021-12-15 23:45:43 +01:00
|
|
|
G()->net_query_dispatcher().update_mtproto_header();
|
|
|
|
}
|
2022-03-30 13:48:23 +02:00
|
|
|
send_closure(td_->attach_menu_manager_actor_, &AttachMenuManager::reload_attach_menu_bots, Promise<Unit>());
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
if (name == "language_pack_version") {
|
|
|
|
send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_pack_version_changed, false, -1);
|
|
|
|
}
|
|
|
|
if (name == "localization_target") {
|
|
|
|
send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_pack_changed);
|
2022-08-18 13:54:57 +02:00
|
|
|
if (G()->mtproto_header().set_language_pack(get_option_string(name))) {
|
2021-12-15 23:45:43 +01:00
|
|
|
G()->net_query_dispatcher().update_mtproto_header();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
if (name == "notification_cloud_delay_ms") {
|
|
|
|
send_closure(td_->notification_manager_actor_, &NotificationManager::on_notification_cloud_delay_changed);
|
|
|
|
}
|
|
|
|
if (name == "notification_default_delay_ms") {
|
|
|
|
send_closure(td_->notification_manager_actor_, &NotificationManager::on_notification_default_delay_changed);
|
|
|
|
}
|
|
|
|
if (name == "notification_group_count_max") {
|
|
|
|
send_closure(td_->notification_manager_actor_, &NotificationManager::on_notification_group_count_max_changed,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
if (name == "notification_group_size_max") {
|
|
|
|
send_closure(td_->notification_manager_actor_, &NotificationManager::on_notification_group_size_max_changed);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (name == "online_cloud_timeout_ms") {
|
|
|
|
send_closure(td_->notification_manager_actor_, &NotificationManager::on_online_cloud_timeout_changed);
|
|
|
|
}
|
|
|
|
if (name == "otherwise_relogin_days") {
|
2022-08-18 13:54:57 +02:00
|
|
|
auto days = narrow_cast<int32>(get_option_integer(name));
|
2021-12-15 23:45:43 +01:00
|
|
|
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") {
|
|
|
|
send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_rating_e_decay);
|
|
|
|
}
|
|
|
|
if (name == "recent_stickers_limit") {
|
2022-08-17 20:40:03 +02:00
|
|
|
td_->stickers_manager_->on_update_recent_stickers_limit();
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (name == "saved_animations_limit") {
|
2022-08-17 20:40:03 +02:00
|
|
|
td_->animations_manager_->on_update_saved_animations_limit();
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
if (name == "session_count") {
|
|
|
|
G()->net_query_dispatcher().update_session_count();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
if (name == "use_pfs") {
|
|
|
|
G()->net_query_dispatcher().update_use_pfs();
|
|
|
|
}
|
|
|
|
if (name == "use_storage_optimizer") {
|
|
|
|
send_closure(td_->storage_manager_, &StorageManager::update_use_storage_optimizer);
|
|
|
|
}
|
|
|
|
if (name == "utc_time_offset") {
|
2022-08-18 13:54:57 +02:00
|
|
|
if (G()->mtproto_header().set_tz_offset(static_cast<int32>(get_option_integer(name)))) {
|
2021-12-15 23:45:43 +01:00
|
|
|
G()->net_query_dispatcher().update_mtproto_header();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 10:07:32 +01:00
|
|
|
void OptionManager::get_option(const string &name, Promise<td_api::object_ptr<td_api::OptionValue>> &&promise) {
|
|
|
|
bool is_bot = td_->auth_manager_ != nullptr && td_->auth_manager_->is_authorized() && td_->auth_manager_->is_bot();
|
2022-08-18 13:54:57 +02:00
|
|
|
auto wrap_promise = [this, &promise, &name] {
|
|
|
|
return PromiseCreator::lambda([this, promise = std::move(promise), name](Unit result) mutable {
|
2021-12-16 10:07:32 +01:00
|
|
|
// the option is already updated on success, ignore errors
|
2022-08-18 13:54:57 +02:00
|
|
|
promise.set_value(get_option_value_object(get_option(name)));
|
2021-12-16 10:07:32 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
switch (name[0]) {
|
|
|
|
// all these options should be added to getCurrentState
|
|
|
|
case 'a':
|
|
|
|
if (!is_bot && name == "archive_and_mute_new_chats_from_unknown_users") {
|
|
|
|
return send_closure_later(td_->config_manager_, &ConfigManager::get_global_privacy_settings, wrap_promise());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (!is_bot && name == "can_ignore_sensitive_content_restrictions") {
|
|
|
|
return send_closure_later(td_->config_manager_, &ConfigManager::get_content_settings, wrap_promise());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
if (!is_bot && name == "disable_contact_registered_notifications") {
|
2022-08-18 18:54:04 +02:00
|
|
|
if (is_td_inited_) {
|
|
|
|
send_closure_later(td_->notification_manager_actor_,
|
|
|
|
&NotificationManager::get_disable_contact_registered_notifications, wrap_promise());
|
|
|
|
} else {
|
|
|
|
pending_get_options_.emplace_back(name, std::move(promise));
|
|
|
|
}
|
|
|
|
return;
|
2021-12-16 10:07:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
if (!is_bot && name == "ignore_sensitive_content_restrictions") {
|
|
|
|
return send_closure_later(td_->config_manager_, &ConfigManager::get_content_settings, wrap_promise());
|
|
|
|
}
|
|
|
|
if (!is_bot && name == "is_location_visible") {
|
2022-08-18 18:54:04 +02:00
|
|
|
if (is_td_inited_) {
|
|
|
|
send_closure_later(td_->contacts_manager_actor_, &ContactsManager::get_is_location_visible, wrap_promise());
|
|
|
|
} else {
|
|
|
|
pending_get_options_.emplace_back(name, std::move(promise));
|
|
|
|
}
|
|
|
|
return;
|
2021-12-16 10:07:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (name == "online") {
|
|
|
|
return promise.set_value(td_api::make_object<td_api::optionValueBoolean>(td_->is_online()));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
if (name == "unix_time") {
|
2021-12-16 13:18:51 +01:00
|
|
|
return promise.set_value(get_unix_time_option_value_object());
|
2021-12-16 10:07:32 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-07-11 12:33:56 +02:00
|
|
|
}
|
|
|
|
wrap_promise().set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2022-07-11 14:36:29 +02:00
|
|
|
td_api::object_ptr<td_api::OptionValue> OptionManager::get_option_synchronously(Slice name) {
|
|
|
|
CHECK(!name.empty());
|
2022-07-11 12:33:56 +02:00
|
|
|
switch (name[0]) {
|
|
|
|
case 'c':
|
|
|
|
if (name == "commit_hash") {
|
2022-07-11 13:01:56 +02:00
|
|
|
return td_api::make_object<td_api::optionValueString>(get_git_commit_hash());
|
2022-07-11 12:33:56 +02:00
|
|
|
}
|
|
|
|
break;
|
2021-12-16 10:07:32 +01:00
|
|
|
case 'v':
|
|
|
|
if (name == "version") {
|
2022-07-31 02:19:36 +02:00
|
|
|
return td_api::make_object<td_api::optionValueString>("1.8.5");
|
2021-12-16 10:07:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 12:33:56 +02:00
|
|
|
UNREACHABLE();
|
2021-12-16 10:07:32 +01:00
|
|
|
}
|
|
|
|
|
2021-12-16 11:13:14 +01:00
|
|
|
void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::OptionValue> &&value,
|
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
int32 value_constructor_id = value == nullptr ? td_api::optionValueEmpty::ID : value->get_id();
|
|
|
|
|
|
|
|
auto set_integer_option = [&](Slice option_name, int64 min_value = 0,
|
|
|
|
int64 max_value = std::numeric_limits<int32>::max()) {
|
|
|
|
if (name != option_name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (value_constructor_id == td_api::optionValueEmpty::ID) {
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_empty(option_name);
|
2021-12-16 11:13:14 +01:00
|
|
|
} else {
|
2022-05-14 19:09:08 +02:00
|
|
|
if (value_constructor_id != td_api::optionValueInteger::ID) {
|
|
|
|
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have integer value"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:13:14 +01:00
|
|
|
int64 int_value = static_cast<td_api::optionValueInteger *>(value.get())->value_;
|
|
|
|
if (int_value < min_value || int_value > max_value) {
|
|
|
|
promise.set_error(Status::Error(400, PSLICE() << "Option's \"" << name << "\" value " << int_value
|
|
|
|
<< " is outside of the valid range [" << min_value << ", "
|
|
|
|
<< max_value << "]"));
|
2022-01-31 16:57:37 +01:00
|
|
|
return false;
|
2021-12-16 11:13:14 +01:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_integer(name, int_value);
|
2021-12-16 11:13:14 +01:00
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto set_boolean_option = [&](Slice option_name) {
|
|
|
|
if (name != option_name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (value_constructor_id == td_api::optionValueEmpty::ID) {
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_empty(name);
|
2021-12-16 11:13:14 +01:00
|
|
|
} else {
|
2022-05-14 19:09:08 +02:00
|
|
|
if (value_constructor_id != td_api::optionValueBoolean::ID) {
|
|
|
|
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have boolean value"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:13:14 +01:00
|
|
|
bool bool_value = static_cast<td_api::optionValueBoolean *>(value.get())->value_;
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_boolean(name, bool_value);
|
2021-12-16 11:13:14 +01:00
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-05-14 19:09:08 +02:00
|
|
|
auto set_string_option = [&](Slice option_name, std::function<bool(Slice)> check_value) {
|
2021-12-16 11:13:14 +01:00
|
|
|
if (name != option_name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (value_constructor_id == td_api::optionValueEmpty::ID) {
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_empty(name);
|
2021-12-16 11:13:14 +01:00
|
|
|
} else {
|
2022-05-14 19:09:08 +02:00
|
|
|
if (value_constructor_id != td_api::optionValueString::ID) {
|
|
|
|
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have string value"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:13:14 +01:00
|
|
|
const string &str_value = static_cast<td_api::optionValueString *>(value.get())->value_;
|
|
|
|
if (str_value.empty()) {
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_empty(name);
|
2021-12-16 11:13:14 +01:00
|
|
|
} else {
|
|
|
|
if (check_value(str_value)) {
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_string(name, str_value);
|
2021-12-16 11:13:14 +01:00
|
|
|
} else {
|
|
|
|
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" can't have specified value"));
|
2022-01-31 16:57:37 +01:00
|
|
|
return false;
|
2021-12-16 11:13:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool is_bot = td_->auth_manager_ != nullptr && td_->auth_manager_->is_authorized() && td_->auth_manager_->is_bot();
|
|
|
|
switch (name[0]) {
|
|
|
|
case 'a':
|
|
|
|
if (set_boolean_option("always_parse_markdown")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && name == "archive_and_mute_new_chats_from_unknown_users") {
|
|
|
|
if (value_constructor_id != td_api::optionValueBoolean::ID &&
|
|
|
|
value_constructor_id != td_api::optionValueEmpty::ID) {
|
|
|
|
return promise.set_error(
|
|
|
|
Status::Error(400, "Option \"archive_and_mute_new_chats_from_unknown_users\" must have boolean value"));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto archive_and_mute = value_constructor_id == td_api::optionValueBoolean::ID &&
|
|
|
|
static_cast<td_api::optionValueBoolean *>(value.get())->value_;
|
|
|
|
send_closure_later(td_->config_manager_, &ConfigManager::set_archive_and_mute, archive_and_mute,
|
|
|
|
std::move(promise));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (!is_bot && set_string_option("connection_parameters", [](Slice value) {
|
|
|
|
string value_copy = value.str();
|
|
|
|
auto r_json_value = get_json_value(value_copy);
|
|
|
|
if (r_json_value.is_error()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return r_json_value.ok()->get_id() == td_api::jsonValueObject::ID;
|
|
|
|
})) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
if (!is_bot && set_boolean_option("disable_animated_emoji")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && set_boolean_option("disable_sent_scheduled_message_notifications")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && set_boolean_option("disable_top_chats")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("disable_persistent_network_statistics")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("disable_time_adjustment_protection")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (name == "drop_notification_ids") {
|
|
|
|
G()->td_db()->get_binlog_pmc()->erase("notification_id_current");
|
|
|
|
G()->td_db()->get_binlog_pmc()->erase("notification_group_id_current");
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
if (set_boolean_option("ignore_background_updates")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("ignore_default_disable_notification")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("ignore_inline_thumbnails")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("ignore_platform_restrictions")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("is_emulator")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && name == "ignore_sensitive_content_restrictions") {
|
2022-08-18 13:54:57 +02:00
|
|
|
if (!get_option_boolean("can_ignore_sensitive_content_restrictions")) {
|
2021-12-16 11:13:14 +01:00
|
|
|
return promise.set_error(
|
|
|
|
Status::Error(400, "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 promise.set_error(
|
|
|
|
Status::Error(400, "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 *>(value.get())->value_;
|
|
|
|
send_closure_later(td_->config_manager_, &ConfigManager::set_content_settings,
|
|
|
|
ignore_sensitive_content_restrictions, std::move(promise));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && set_boolean_option("is_location_visible")) {
|
2022-08-19 13:16:53 +02:00
|
|
|
ContactsManager::set_location_visibility(td_);
|
2021-12-16 11:13:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (!is_bot && set_string_option("language_pack_database_path", [](Slice value) { return true; })) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && set_string_option("localization_target", LanguagePackManager::check_language_pack_name)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot && set_string_option("language_pack_id", LanguagePackManager::check_language_code_name)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (set_integer_option("message_unload_delay", 60, 86400)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
if (!is_bot &&
|
|
|
|
set_integer_option("notification_group_count_max", NotificationManager::MIN_NOTIFICATION_GROUP_COUNT_MAX,
|
|
|
|
NotificationManager::MAX_NOTIFICATION_GROUP_COUNT_MAX)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!is_bot &&
|
|
|
|
set_integer_option("notification_group_size_max", NotificationManager::MIN_NOTIFICATION_GROUP_SIZE_MAX,
|
|
|
|
NotificationManager::MAX_NOTIFICATION_GROUP_SIZE_MAX)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (name == "online") {
|
|
|
|
if (value_constructor_id != td_api::optionValueBoolean::ID &&
|
|
|
|
value_constructor_id != td_api::optionValueEmpty::ID) {
|
|
|
|
return promise.set_error(Status::Error(400, "Option \"online\" must have boolean value"));
|
|
|
|
}
|
|
|
|
bool is_online = value_constructor_id == td_api::optionValueEmpty::ID ||
|
|
|
|
static_cast<const td_api::optionValueBoolean *>(value.get())->value_;
|
2022-05-12 15:40:53 +02:00
|
|
|
td_->set_is_online(is_online);
|
2021-12-16 11:13:14 +01:00
|
|
|
if (!is_bot) {
|
|
|
|
send_closure(td_->state_manager_, &StateManager::on_online, is_online);
|
|
|
|
}
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
if (set_boolean_option("prefer_ipv6")) {
|
|
|
|
send_closure(td_->state_manager_, &StateManager::on_network_updated);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
// temporary option
|
|
|
|
if (set_boolean_option("reuse_uploaded_photos_by_hash")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (set_integer_option("storage_max_files_size")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_integer_option("storage_max_time_from_last_access")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_integer_option("storage_max_file_count")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_integer_option("storage_immunity_delay")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("store_all_files_in_files_directory")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (set_boolean_option("test_flood_wait")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
if (set_boolean_option("use_pfs")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("use_quick_ack")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_boolean_option("use_storage_optimizer")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set_integer_option("utc_time_offset", -12 * 60 * 60, 14 * 60 * 60)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
case 'x': {
|
|
|
|
if (name.size() > 255) {
|
|
|
|
return promise.set_error(Status::Error(400, "Option name is too long"));
|
|
|
|
}
|
|
|
|
switch (value_constructor_id) {
|
|
|
|
case td_api::optionValueBoolean::ID:
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_boolean(name, static_cast<const td_api::optionValueBoolean *>(value.get())->value_);
|
2021-12-16 11:13:14 +01:00
|
|
|
break;
|
|
|
|
case td_api::optionValueEmpty::ID:
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_empty(name);
|
2021-12-16 11:13:14 +01:00
|
|
|
break;
|
|
|
|
case td_api::optionValueInteger::ID:
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_integer(name, static_cast<const td_api::optionValueInteger *>(value.get())->value_);
|
2021-12-16 11:13:14 +01:00
|
|
|
break;
|
|
|
|
case td_api::optionValueString::ID:
|
2022-08-18 13:54:57 +02:00
|
|
|
set_option_string(name, static_cast<const td_api::optionValueString *>(value.get())->value_);
|
2021-12-16 11:13:14 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-31 16:57:37 +01:00
|
|
|
if (promise) {
|
|
|
|
promise.set_error(Status::Error(400, "Option can't be set"));
|
|
|
|
}
|
2021-12-16 11:13:14 +01:00
|
|
|
}
|
|
|
|
|
2021-12-16 20:56:19 +01:00
|
|
|
td_api::object_ptr<td_api::OptionValue> OptionManager::get_option_value_object(Slice value) {
|
|
|
|
if (value.empty()) {
|
|
|
|
return td_api::make_object<td_api::optionValueEmpty>();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (value[0]) {
|
|
|
|
case 'B':
|
|
|
|
if (value == "Btrue") {
|
|
|
|
return td_api::make_object<td_api::optionValueBoolean>(true);
|
|
|
|
}
|
|
|
|
if (value == "Bfalse") {
|
|
|
|
return td_api::make_object<td_api::optionValueBoolean>(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
return td_api::make_object<td_api::optionValueInteger>(to_integer<int64>(value.substr(1)));
|
|
|
|
case 'S':
|
|
|
|
return td_api::make_object<td_api::optionValueString>(value.substr(1).str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return td_api::make_object<td_api::optionValueString>(value.str());
|
|
|
|
}
|
|
|
|
|
2022-07-11 14:36:29 +02:00
|
|
|
void OptionManager::get_common_state(vector<td_api::object_ptr<td_api::Update>> &updates) {
|
|
|
|
for (auto option_name : get_synchronous_options()) {
|
|
|
|
updates.push_back(
|
|
|
|
td_api::make_object<td_api::updateOption>(option_name.str(), get_option_synchronously(option_name)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 10:16:09 +01:00
|
|
|
void OptionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
2022-07-11 14:36:29 +02:00
|
|
|
get_common_state(updates);
|
2021-12-16 10:16:09 +01:00
|
|
|
|
2021-12-16 11:13:14 +01:00
|
|
|
updates.push_back(td_api::make_object<td_api::updateOption>(
|
|
|
|
"online", td_api::make_object<td_api::optionValueBoolean>(td_->is_online())));
|
2021-12-16 13:18:51 +01:00
|
|
|
|
|
|
|
updates.push_back(td_api::make_object<td_api::updateOption>("unix_time", get_unix_time_option_value_object()));
|
2021-12-16 10:16:09 +01:00
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
for (const auto &option : options_->get_all()) {
|
2021-12-15 23:45:43 +01:00
|
|
|
if (!is_internal_option(option.first)) {
|
2021-12-16 20:56:19 +01:00
|
|
|
updates.push_back(
|
|
|
|
td_api::make_object<td_api::updateOption>(option.first, get_option_value_object(option.second)));
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
} // namespace td
|