2021-12-15 23:09:59 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
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"
|
|
|
|
|
2023-09-12 14:44:57 +02:00
|
|
|
#include "td/telegram/AccountManager.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"
|
2024-04-02 12:06:22 +02:00
|
|
|
#include "td/telegram/ChatManager.h"
|
2021-12-16 10:07:32 +01:00
|
|
|
#include "td/telegram/ConfigManager.h"
|
2022-12-20 13:01:39 +01:00
|
|
|
#include "td/telegram/CountryInfoManager.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"
|
|
|
|
#include "td/telegram/net/MtprotoHeader.h"
|
|
|
|
#include "td/telegram/net/NetQueryDispatcher.h"
|
|
|
|
#include "td/telegram/NotificationManager.h"
|
2024-03-10 23:42:08 +01:00
|
|
|
#include "td/telegram/PeopleNearbyManager.h"
|
2023-08-04 17:39:07 +02:00
|
|
|
#include "td/telegram/ReactionType.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"
|
2023-06-16 16:55:54 +02:00
|
|
|
#include "td/telegram/StoryManager.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#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"
|
2024-04-02 02:52:34 +02:00
|
|
|
#include "td/telegram/UserManager.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
|
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"
|
2024-01-25 18:06:07 +01:00
|
|
|
#include "td/utils/FlatHashSet.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)
|
2022-10-04 20:08:07 +02:00
|
|
|
: td_(td)
|
|
|
|
, current_scheduler_id_(Scheduler::instance()->sched_id())
|
|
|
|
, 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
|
|
|
|
2024-01-23 18:36:29 +01:00
|
|
|
auto &options = options_->inner();
|
|
|
|
|
2024-01-23 17:42:28 +01:00
|
|
|
option_pmc_->for_each([&](Slice name, Slice value) {
|
|
|
|
if (name == "utc_time_offset") {
|
|
|
|
return;
|
|
|
|
}
|
2023-07-27 12:58:20 +02:00
|
|
|
CHECK(!name.empty());
|
2024-01-23 18:36:29 +01:00
|
|
|
options.set(name, value);
|
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,
|
2024-01-23 17:42:28 +01:00
|
|
|
td_api::make_object<td_api::updateOption>(name.str(), get_option_value_object(value)));
|
2023-01-17 12:24:18 +01:00
|
|
|
} else {
|
|
|
|
auto update = get_internal_option_update(name);
|
|
|
|
if (update != nullptr) {
|
|
|
|
send_closure(G()->td(), &Td::send_update, std::move(update));
|
2022-10-06 17:11:02 +02:00
|
|
|
}
|
2022-08-18 13:54:57 +02:00
|
|
|
}
|
2024-01-23 17:42:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
auto utc_time_offset = PSTRING() << 'I' << Clocks::tz_offset();
|
2024-01-23 18:36:29 +01:00
|
|
|
options.set("utc_time_offset", utc_time_offset);
|
2024-01-23 17:42:28 +01:00
|
|
|
send_closure(G()->td(), &Td::send_update,
|
|
|
|
td_api::make_object<td_api::updateOption>("utc_time_offset", get_option_value_object(utc_time_offset)));
|
2022-08-18 13:54:57 +02:00
|
|
|
|
2024-01-24 13:01:14 +01:00
|
|
|
bool is_test_dc = G()->is_test_dc();
|
2024-01-24 12:59:09 +01:00
|
|
|
auto set_default_integer_option = [&](string name, int64 value) {
|
2024-01-23 18:36:29 +01:00
|
|
|
if (options.isset(name)) {
|
2024-01-23 18:29:31 +01:00
|
|
|
return;
|
2024-01-23 18:16:26 +01:00
|
|
|
}
|
2024-01-23 18:29:31 +01:00
|
|
|
auto str_value = PSTRING() << 'I' << value;
|
2024-01-23 18:36:29 +01:00
|
|
|
options.set(name, str_value);
|
2024-01-23 18:29:31 +01:00
|
|
|
option_pmc_->set(name, str_value);
|
2024-01-23 18:16:26 +01:00
|
|
|
|
2024-01-23 18:29:31 +01:00
|
|
|
if (!is_internal_option(name)) {
|
|
|
|
send_closure(
|
|
|
|
G()->td(), &Td::send_update,
|
|
|
|
td_api::make_object<td_api::updateOption>(name, td_api::make_object<td_api::optionValueInteger>(value)));
|
|
|
|
}
|
|
|
|
};
|
2024-01-24 12:59:09 +01:00
|
|
|
set_default_integer_option("telegram_service_notifications_chat_id",
|
2024-04-02 02:52:34 +02:00
|
|
|
DialogId(UserManager::get_service_notifications_user_id()).get());
|
|
|
|
set_default_integer_option("replies_bot_chat_id", DialogId(UserManager::get_replies_bot_user_id()).get());
|
|
|
|
set_default_integer_option("group_anonymous_bot_user_id", UserManager::get_anonymous_bot_user_id().get());
|
|
|
|
set_default_integer_option("channel_bot_user_id", UserManager::get_channel_bot_user_id().get());
|
|
|
|
set_default_integer_option("anti_spam_bot_user_id", UserManager::get_anti_spam_bot_user_id().get());
|
2024-01-23 18:16:26 +01:00
|
|
|
set_default_integer_option("message_caption_length_max", 1024);
|
|
|
|
set_default_integer_option("message_reply_quote_length_max", 1024);
|
|
|
|
set_default_integer_option("story_caption_length_max", 200);
|
|
|
|
set_default_integer_option("bio_length_max", 70);
|
|
|
|
set_default_integer_option("suggested_video_note_length", 384);
|
|
|
|
set_default_integer_option("suggested_video_note_video_bitrate", 1000);
|
|
|
|
set_default_integer_option("suggested_video_note_audio_bitrate", 64);
|
|
|
|
set_default_integer_option("notification_sound_duration_max", 5);
|
|
|
|
set_default_integer_option("notification_sound_size_max", 307200);
|
2024-01-24 13:01:14 +01:00
|
|
|
set_default_integer_option("notification_sound_count_max", is_test_dc ? 5 : 100);
|
|
|
|
set_default_integer_option("chat_folder_count_max", is_test_dc ? 3 : 10);
|
|
|
|
set_default_integer_option("chat_folder_chosen_chat_count_max", is_test_dc ? 5 : 100);
|
|
|
|
set_default_integer_option("aggressive_anti_spam_supergroup_member_count_min", is_test_dc ? 1 : 100);
|
|
|
|
set_default_integer_option("pinned_forum_topic_count_max", is_test_dc ? 3 : 5);
|
2024-01-23 18:16:26 +01:00
|
|
|
set_default_integer_option("story_stealth_mode_past_period", 300);
|
|
|
|
set_default_integer_option("story_stealth_mode_future_period", 1500);
|
|
|
|
set_default_integer_option("story_stealth_mode_cooldown_period", 3600);
|
2024-01-24 13:01:14 +01:00
|
|
|
set_default_integer_option("giveaway_additional_chat_count_max", is_test_dc ? 3 : 10);
|
|
|
|
set_default_integer_option("giveaway_country_count_max", is_test_dc ? 3 : 10);
|
2024-01-23 18:16:26 +01:00
|
|
|
set_default_integer_option("giveaway_boost_count_per_premium", 4);
|
|
|
|
set_default_integer_option("giveaway_duration_max", 7 * 86400);
|
|
|
|
set_default_integer_option("premium_gift_boost_count", 3);
|
2024-01-24 13:01:14 +01:00
|
|
|
set_default_integer_option("chat_boost_level_max", is_test_dc ? 10 : 100);
|
2024-01-23 18:16:26 +01:00
|
|
|
set_default_integer_option("chat_available_reaction_count_max", 100);
|
2024-01-24 13:01:14 +01:00
|
|
|
set_default_integer_option("channel_bg_icon_level_min", is_test_dc ? 1 : 4);
|
|
|
|
set_default_integer_option("channel_custom_wallpaper_level_min", is_test_dc ? 4 : 10);
|
|
|
|
set_default_integer_option("channel_emoji_status_level_min", is_test_dc ? 2 : 8);
|
|
|
|
set_default_integer_option("channel_profile_bg_icon_level_min", is_test_dc ? 1 : 7);
|
2024-04-02 13:36:38 +02:00
|
|
|
set_default_integer_option("channel_restrict_sponsored_level_min", is_test_dc ? 5 : 50);
|
2024-01-24 13:01:14 +01:00
|
|
|
set_default_integer_option("channel_wallpaper_level_min", is_test_dc ? 3 : 9);
|
2024-01-09 11:41:59 +01:00
|
|
|
set_default_integer_option("pm_read_date_expire_period", 604800);
|
2024-02-09 12:03:53 +01:00
|
|
|
set_default_integer_option("group_transcribe_level_min", is_test_dc ? 4 : 6);
|
|
|
|
set_default_integer_option("group_emoji_stickers_level_min", is_test_dc ? 1 : 4);
|
|
|
|
set_default_integer_option("group_profile_bg_icon_level_min", is_test_dc ? 1 : 5);
|
|
|
|
set_default_integer_option("group_emoji_status_level_min", is_test_dc ? 2 : 8);
|
|
|
|
set_default_integer_option("group_wallpaper_level_min", is_test_dc ? 3 : 9);
|
|
|
|
set_default_integer_option("group_custom_wallpaper_level_min", is_test_dc ? 4 : 10);
|
2024-03-04 11:27:23 +01:00
|
|
|
set_default_integer_option("quick_reply_shortcut_count_max", is_test_dc ? 10 : 100);
|
2024-03-05 12:44:57 +01:00
|
|
|
set_default_integer_option("quick_reply_shortcut_message_count_max", 20);
|
2024-03-19 13:31:17 +01:00
|
|
|
set_default_integer_option("business_intro_title_length_max", 32);
|
|
|
|
set_default_integer_option("business_intro_message_length_max", 70);
|
2022-12-21 10:26:29 +01:00
|
|
|
|
2024-01-23 19:03:04 +01:00
|
|
|
if (options.isset("my_phone_number") || !options.isset("my_id")) {
|
|
|
|
update_premium_options();
|
|
|
|
}
|
2023-12-08 10:57:13 +01:00
|
|
|
|
2023-07-14 14:41:38 +02:00
|
|
|
set_option_empty("archive_and_mute_new_chats_from_unknown_users");
|
2023-12-26 17:20:06 +01:00
|
|
|
set_option_empty("channel_custom_accent_color_boost_level_min");
|
2023-04-03 16:28:51 +02:00
|
|
|
set_option_empty("chat_filter_count_max");
|
|
|
|
set_option_empty("chat_filter_chosen_chat_count_max");
|
2022-12-30 22:17:18 +01:00
|
|
|
set_option_empty("forum_member_count_min");
|
2022-12-21 10:26:29 +01:00
|
|
|
set_option_empty("themed_emoji_statuses_sticker_set_id");
|
2022-12-28 16:42:11 +01:00
|
|
|
set_option_empty("themed_premium_statuses_sticker_set_id");
|
2021-12-15 23:09:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OptionManager::~OptionManager() = default;
|
|
|
|
|
2023-12-08 10:57:13 +01:00
|
|
|
void OptionManager::update_premium_options() {
|
|
|
|
bool is_premium = get_option_boolean("is_premium");
|
|
|
|
if (is_premium) {
|
|
|
|
set_option_integer("saved_animations_limit", get_option_integer("saved_gifs_limit_premium", 400));
|
|
|
|
set_option_integer("favorite_stickers_limit", get_option_integer("stickers_faved_limit_premium", 10));
|
|
|
|
set_option_integer("chat_folder_count_max", get_option_integer("dialog_filters_limit_premium", 20));
|
|
|
|
set_option_integer("chat_folder_chosen_chat_count_max",
|
|
|
|
get_option_integer("dialog_filters_chats_limit_premium", 200));
|
2024-01-18 16:34:39 +01:00
|
|
|
set_option_integer("pinned_chat_count_max", get_option_integer("dialogs_pinned_limit_premium", 100));
|
2023-12-08 10:57:13 +01:00
|
|
|
set_option_integer("pinned_archived_chat_count_max",
|
|
|
|
get_option_integer("dialogs_folder_pinned_limit_premium", 200));
|
2024-01-18 16:34:39 +01:00
|
|
|
set_option_integer("pinned_saved_messages_topic_count_max",
|
|
|
|
get_option_integer("saved_dialogs_pinned_limit_premium", 100));
|
2023-12-08 10:57:13 +01:00
|
|
|
set_option_integer("bio_length_max", get_option_integer("about_length_limit_premium", 140));
|
|
|
|
set_option_integer("chat_folder_invite_link_count_max", get_option_integer("chatlist_invites_limit_premium", 20));
|
|
|
|
set_option_integer("added_shareable_chat_folder_count_max",
|
|
|
|
get_option_integer("chatlists_joined_limit_premium", 20));
|
|
|
|
set_option_integer("active_story_count_max", get_option_integer("story_expiring_limit_premium", 100));
|
|
|
|
set_option_integer("story_caption_length_max", get_option_integer("story_caption_length_limit_premium", 2048));
|
|
|
|
set_option_integer("weekly_sent_story_count_max", get_option_integer("stories_sent_weekly_limit_premium", 700));
|
|
|
|
set_option_integer("monthly_sent_story_count_max", get_option_integer("stories_sent_monthly_limit_premium", 3000));
|
|
|
|
set_option_integer("story_suggested_reaction_area_count_max",
|
|
|
|
get_option_integer("stories_suggested_reactions_limit_premium", 5));
|
2024-03-29 14:31:49 +01:00
|
|
|
|
2024-03-29 14:51:53 +01:00
|
|
|
set_option_boolean("can_set_new_chat_privacy_settings", true);
|
2024-03-29 14:31:49 +01:00
|
|
|
set_option_boolean("can_use_text_entities_in_story_caption", true);
|
2023-12-08 10:57:13 +01:00
|
|
|
} else {
|
|
|
|
set_option_integer("saved_animations_limit", get_option_integer("saved_gifs_limit_default", 200));
|
|
|
|
set_option_integer("favorite_stickers_limit", get_option_integer("stickers_faved_limit_default", 5));
|
|
|
|
set_option_integer("chat_folder_count_max", get_option_integer("dialog_filters_limit_default", 10));
|
|
|
|
set_option_integer("chat_folder_chosen_chat_count_max",
|
|
|
|
get_option_integer("dialog_filters_chats_limit_default", 100));
|
2024-01-18 16:34:39 +01:00
|
|
|
set_option_integer("pinned_chat_count_max", get_option_integer("dialogs_pinned_limit_default", 5));
|
2023-12-08 10:57:13 +01:00
|
|
|
set_option_integer("pinned_archived_chat_count_max",
|
|
|
|
get_option_integer("dialogs_folder_pinned_limit_default", 100));
|
2024-01-18 16:34:39 +01:00
|
|
|
set_option_integer("pinned_saved_messages_topic_count_max",
|
|
|
|
get_option_integer("saved_dialogs_pinned_limit_default", 5));
|
2023-12-08 10:57:13 +01:00
|
|
|
set_option_integer("bio_length_max", get_option_integer("about_length_limit_default", 70));
|
|
|
|
set_option_integer("chat_folder_invite_link_count_max", get_option_integer("chatlist_invites_limit_default", 3));
|
|
|
|
set_option_integer("added_shareable_chat_folder_count_max",
|
|
|
|
get_option_integer("chatlists_joined_limit_default", 2));
|
|
|
|
set_option_integer("active_story_count_max", get_option_integer("story_expiring_limit_default", 3));
|
|
|
|
set_option_integer("story_caption_length_max", get_option_integer("story_caption_length_limit_default", 200));
|
|
|
|
set_option_integer("weekly_sent_story_count_max", get_option_integer("stories_sent_weekly_limit_default", 7));
|
|
|
|
set_option_integer("monthly_sent_story_count_max", get_option_integer("stories_sent_monthly_limit_default", 30));
|
|
|
|
set_option_integer("story_suggested_reaction_area_count_max",
|
|
|
|
get_option_integer("stories_suggested_reactions_limit_default", 1));
|
2024-03-29 14:31:49 +01:00
|
|
|
|
2024-03-29 14:51:53 +01:00
|
|
|
set_option_boolean("can_set_new_chat_privacy_settings", !get_option_boolean("need_premium_for_new_chat_privacy"));
|
2024-03-29 14:31:49 +01:00
|
|
|
set_option_boolean("can_use_text_entities_in_story_caption",
|
|
|
|
!get_option_boolean("need_premium_for_story_caption_entities"));
|
2023-12-08 10:57:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
2022-10-04 20:08:07 +02:00
|
|
|
CHECK(Scheduler::instance()->sched_id() == current_scheduler_id_);
|
2022-08-18 13:54:57 +02:00
|
|
|
if (value.empty()) {
|
2023-01-17 11:55:51 +01:00
|
|
|
if (options_->erase(name.str()) == 0) {
|
2022-08-18 13:54:57 +02:00
|
|
|
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))));
|
2023-01-17 12:24:18 +01:00
|
|
|
} else {
|
|
|
|
auto update = get_internal_option_update(name);
|
|
|
|
if (update != nullptr) {
|
|
|
|
send_closure(G()->td(), &Td::send_update, std::move(update));
|
|
|
|
}
|
2022-08-18 18:12:15 +02:00
|
|
|
}
|
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
|
|
|
bool OptionManager::is_internal_option(Slice name) {
|
2024-01-25 16:50:37 +01:00
|
|
|
static const FlatHashSet<Slice, SliceHash> internal_options{"about_length_limit_default",
|
|
|
|
"about_length_limit_premium",
|
|
|
|
"aggressive_anti_spam_supergroup_member_count_min",
|
|
|
|
"animated_emoji_zoom",
|
|
|
|
"animation_search_emojis",
|
|
|
|
"animation_search_provider",
|
|
|
|
"authorization_autoconfirm_period",
|
|
|
|
"base_language_pack_version",
|
2024-03-28 23:14:59 +01:00
|
|
|
"business_features",
|
2024-01-25 16:50:37 +01:00
|
|
|
"call_receive_timeout_ms",
|
|
|
|
"call_ring_timeout_ms",
|
|
|
|
"caption_length_limit_default",
|
|
|
|
"caption_length_limit_premium",
|
|
|
|
"channel_bg_icon_level_min",
|
|
|
|
"channel_custom_wallpaper_level_min",
|
|
|
|
"channel_emoji_status_level_min",
|
|
|
|
"channel_profile_bg_icon_level_min",
|
2024-04-02 13:36:38 +02:00
|
|
|
"channel_restrict_sponsored_level_min",
|
2024-01-25 16:50:37 +01:00
|
|
|
"channel_wallpaper_level_min",
|
|
|
|
"channels_limit_default",
|
|
|
|
"channels_limit_premium",
|
|
|
|
"channels_public_limit_default",
|
|
|
|
"channels_public_limit_premium",
|
|
|
|
"channels_read_media_period",
|
|
|
|
"chat_read_mark_expire_period",
|
|
|
|
"chat_read_mark_size_threshold",
|
|
|
|
"chatlist_invites_limit_default",
|
|
|
|
"chatlist_invites_limit_premium",
|
|
|
|
"chatlists_joined_limit_default",
|
|
|
|
"chatlists_joined_limit_premium",
|
|
|
|
"dc_txt_domain_name",
|
|
|
|
"default_reaction",
|
|
|
|
"default_reaction_needs_sync",
|
|
|
|
"dialog_filters_chats_limit_default",
|
|
|
|
"dialog_filters_chats_limit_premium",
|
|
|
|
"dialog_filters_limit_default",
|
|
|
|
"dialog_filters_limit_premium",
|
|
|
|
"dialogs_folder_pinned_limit_default",
|
|
|
|
"dialogs_folder_pinned_limit_premium",
|
|
|
|
"dialogs_pinned_limit_default",
|
|
|
|
"dialogs_pinned_limit_premium",
|
|
|
|
"dice_emojis",
|
|
|
|
"dice_success_values",
|
|
|
|
"edit_time_limit",
|
|
|
|
"emoji_sounds",
|
|
|
|
"fragment_prefixes",
|
2024-02-09 12:03:53 +01:00
|
|
|
"group_transcribe_level_min",
|
|
|
|
"group_emoji_stickers_level_min",
|
|
|
|
"group_profile_bg_icon_level_min",
|
|
|
|
"group_emoji_status_level_min",
|
|
|
|
"group_wallpaper_level_min",
|
|
|
|
"group_custom_wallpaper_level_min",
|
2024-01-25 16:50:37 +01:00
|
|
|
"hidden_members_group_size_min",
|
|
|
|
"ignored_restriction_reasons",
|
|
|
|
"language_pack_version",
|
|
|
|
"my_phone_number",
|
2024-03-29 14:51:53 +01:00
|
|
|
"need_premium_for_new_chat_privacy",
|
2024-01-25 16:50:37 +01:00
|
|
|
"need_premium_for_story_caption_entities",
|
|
|
|
"need_synchronize_archive_all_stories",
|
|
|
|
"notification_cloud_delay_ms",
|
|
|
|
"notification_default_delay_ms",
|
|
|
|
"online_cloud_timeout_ms",
|
|
|
|
"online_update_period_ms",
|
|
|
|
"otherwise_relogin_days",
|
|
|
|
"pm_read_date_expire_period",
|
|
|
|
"premium_bot_username",
|
|
|
|
"premium_features",
|
|
|
|
"premium_invoice_slug",
|
|
|
|
"rating_e_decay",
|
|
|
|
"reactions_uniq_max",
|
|
|
|
"reactions_user_max_default",
|
|
|
|
"reactions_user_max_premium",
|
|
|
|
"recent_stickers_limit",
|
|
|
|
"recommended_channels_limit_default",
|
|
|
|
"recommended_channels_limit_premium",
|
|
|
|
"restriction_add_platforms",
|
|
|
|
"revoke_pm_inbox",
|
|
|
|
"revoke_time_limit",
|
|
|
|
"revoke_pm_time_limit",
|
|
|
|
"saved_animations_limit",
|
|
|
|
"saved_dialogs_pinned_limit_default",
|
|
|
|
"saved_dialogs_pinned_limit_premium",
|
|
|
|
"saved_gifs_limit_default",
|
|
|
|
"saved_gifs_limit_premium",
|
|
|
|
"session_count",
|
|
|
|
"since_last_open",
|
|
|
|
"stickers_faved_limit_default",
|
|
|
|
"stickers_faved_limit_premium",
|
|
|
|
"stickers_normal_by_emoji_per_premium_num",
|
|
|
|
"stickers_premium_by_emoji_num",
|
|
|
|
"stories_changelog_user_id",
|
|
|
|
"stories_sent_monthly_limit_default",
|
|
|
|
"stories_sent_monthly_limit_premium",
|
|
|
|
"stories_sent_weekly_limit_default",
|
|
|
|
"stories_sent_weekly_limit_premium",
|
|
|
|
"stories_suggested_reactions_limit_default",
|
|
|
|
"stories_suggested_reactions_limit_premium",
|
|
|
|
"story_caption_length_limit_default",
|
|
|
|
"story_caption_length_limit_premium",
|
|
|
|
"story_expiring_limit_default",
|
|
|
|
"story_expiring_limit_premium",
|
|
|
|
"video_note_size_max",
|
|
|
|
"webfile_dc_id"};
|
|
|
|
return internal_options.count(name) > 0;
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
|
2023-01-17 12:24:18 +01:00
|
|
|
td_api::object_ptr<td_api::Update> OptionManager::get_internal_option_update(Slice name) const {
|
|
|
|
if (name == "default_reaction") {
|
2023-08-04 17:39:07 +02:00
|
|
|
return ReactionType(get_option_string(name)).get_update_default_reaction_type();
|
2023-01-17 12:24:18 +01:00
|
|
|
}
|
|
|
|
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}};
|
2023-01-17 11:22:21 +01:00
|
|
|
return get_update_suggested_actions_object(added_actions, {}, "get_internal_option_update");
|
2023-01-17 12:24:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-09-12 14:44:57 +02:00
|
|
|
if (name == "authorization_autoconfirm_period") {
|
|
|
|
td_->account_manager_->update_unconfirmed_authorization_timeout(true);
|
|
|
|
}
|
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':
|
|
|
|
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
|
|
|
}
|
2022-11-29 21:42:29 +01:00
|
|
|
if (name == "fragment_prefixes") {
|
2022-12-20 13:01:39 +01:00
|
|
|
send_closure(td_->country_info_manager_actor_, &CountryInfoManager::on_update_fragment_prefixes);
|
2022-11-29 21:42:29 +01:00
|
|
|
}
|
2021-12-15 23:45:43 +01:00
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
if (name == "ignored_restriction_reasons") {
|
2024-04-02 12:06:22 +02:00
|
|
|
send_closure(td_->chat_manager_actor_, &ChatManager::on_ignored_restriction_reasons_changed);
|
2024-04-02 02:52:34 +02:00
|
|
|
send_closure(td_->user_manager_actor_, &UserManager::on_ignored_restriction_reasons_changed);
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2023-08-09 14:27:28 +02:00
|
|
|
if (name == "is_premium") {
|
2024-03-29 14:31:49 +01:00
|
|
|
update_premium_options();
|
2023-08-09 14:27:28 +02:00
|
|
|
}
|
2021-12-15 23:45:43 +01:00
|
|
|
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;
|
2024-03-29 15:37:44 +01:00
|
|
|
case 'm':
|
|
|
|
if (name == "my_phone_number") {
|
|
|
|
send_closure(G()->config_manager(), &ConfigManager::reget_config, Promise<Unit>());
|
|
|
|
}
|
|
|
|
break;
|
2021-12-15 23:45:43 +01:00
|
|
|
case 'n':
|
2024-03-29 14:51:53 +01:00
|
|
|
if (name == "need_premium_for_new_chat_privacy") {
|
|
|
|
update_premium_options();
|
|
|
|
}
|
2023-08-09 14:27:28 +02:00
|
|
|
if (name == "need_premium_for_story_caption_entities") {
|
2024-03-29 14:31:49 +01:00
|
|
|
update_premium_options();
|
2023-08-09 14:27:28 +02:00
|
|
|
}
|
2023-06-16 16:55:54 +02:00
|
|
|
if (name == "need_synchronize_archive_all_stories") {
|
|
|
|
send_closure(td_->story_manager_actor_, &StoryManager::try_synchronize_archive_all_stories);
|
|
|
|
}
|
2021-12-15 23:45:43 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
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 '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_) {
|
2024-03-10 23:42:08 +01:00
|
|
|
send_closure_later(td_->people_nearby_manager_actor_, &PeopleNearbyManager::get_is_location_visible,
|
|
|
|
wrap_promise());
|
2022-08-18 18:54:04 +02:00
|
|
|
} 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") {
|
2024-03-31 18:24:45 +02:00
|
|
|
return td_api::make_object<td_api::optionValueString>("1.8.27");
|
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;
|
|
|
|
}
|
2023-08-12 20:53:02 +02:00
|
|
|
/*
|
2023-06-16 16:55:54 +02:00
|
|
|
if (!is_bot && set_boolean_option("archive_all_stories")) {
|
|
|
|
set_option_boolean("need_synchronize_archive_all_stories", true);
|
|
|
|
return;
|
|
|
|
}
|
2023-08-12 20:53:02 +02:00
|
|
|
*/
|
2021-12-16 11:13:14 +01:00
|
|
|
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;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (set_boolean_option("disable_network_statistics")) {
|
2021-12-16 11:13:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (set_boolean_option("disable_persistent_network_statistics")) {
|
2021-12-16 11:13:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (!is_bot && set_boolean_option("disable_sent_scheduled_message_notifications")) {
|
2023-03-13 15:26:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (set_boolean_option("disable_time_adjustment_protection")) {
|
2021-12-16 11:13:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (!is_bot && set_boolean_option("disable_top_chats")) {
|
2021-12-16 11:13:14 +01:00
|
|
|
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;
|
|
|
|
}
|
2023-03-13 17:19:13 +01:00
|
|
|
if (set_boolean_option("ignore_file_names")) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-16 11:13:14 +01:00
|
|
|
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")) {
|
2024-03-10 23:42:08 +01:00
|
|
|
PeopleNearbyManager::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;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (!is_bot && set_string_option("language_pack_id", LanguagePackManager::check_language_code_name)) {
|
2021-12-16 11:13:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-02-15 14:32:03 +01:00
|
|
|
if (!is_bot && set_string_option("localization_target", LanguagePackManager::check_language_pack_name)) {
|
2021-12-16 11:13:14 +01:00
|
|
|
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;
|
|
|
|
}
|
2024-01-19 20:23:26 +01:00
|
|
|
if (set_boolean_option("process_pinned_messages_as_mentions")) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-16 11:13:14 +01:00
|
|
|
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)));
|
2023-01-17 12:24:18 +01:00
|
|
|
} else {
|
|
|
|
auto update = get_internal_option_update(option.first);
|
|
|
|
if (update != nullptr) {
|
|
|
|
updates.push_back(std::move(update));
|
|
|
|
}
|
2021-12-15 23:45:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
} // namespace td
|