From c1e3f2d65d6d32367685b40a52a9924e4efcfd8f Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Mar 2018 23:50:38 +0300 Subject: [PATCH] Use new config constants. GitOrigin-RevId: 6f0d02a9ca91e7db2d416eb89861080ff9f6f30c --- td/telegram/ConfigManager.cpp | 6 ++++++ td/telegram/MessagesManager.cpp | 16 +++++++++++----- td/telegram/Td.cpp | 17 ++++++++++------- td/telegram/Td.h | 2 ++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index b261720c..75d64c0a 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -679,6 +679,12 @@ void ConfigManager::process_config(tl_object_ptr config) { } } + shared_config.set_option_integer("edit_time_limit", config->edit_time_limit_); + shared_config.set_option_boolean("revoke_pm_inbox", + (config->flags_ & telegram_api::config::REVOKE_PM_INBOX_MASK) != 0); + shared_config.set_option_integer("revoke_time_limit", config->revoke_time_limit_); + shared_config.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_); + shared_config.set_option_integer("rating_e_decay", config->rating_e_decay_); if (is_from_main_dc) { diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index dbaa2a4e..9a80b3a8 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -7411,8 +7411,13 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c CHECK(m->message_id.is_server()); bool is_appointed_administrator = false; + bool can_revoke_incoming = false; + const int32 DEFAULT_REVOKE_TIME_LIMIT = 2 * 86400; + int32 revoke_time_limit = G()->shared_config().get_option_integer("revoke_time_limit", DEFAULT_REVOKE_TIME_LIMIT); switch (dialog_id.get_type()) { case DialogType::User: + can_revoke_incoming = G()->shared_config().get_option_boolean("revoke_pm_inbox"); + revoke_time_limit = G()->shared_config().get_option_integer("revoke_pm_time_limit", DEFAULT_REVOKE_TIME_LIMIT); break; case DialogType::Chat: is_appointed_administrator = td_->contacts_manager_->is_appointed_chat_administrator(dialog_id.get_chat_id()); @@ -7428,9 +7433,9 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c return false; } - // TODO use const from the config - return ((m->is_outgoing && !is_service_message_content(m->content->get_id())) || is_appointed_administrator) && - G()->unix_time_cached() < m->date + 2 * 86400; + return (((m->is_outgoing || can_revoke_incoming) && !is_service_message_content(m->content->get_id())) || + is_appointed_administrator) && + G()->unix_time_cached() - m->date <= revoke_time_limit; } void MessagesManager::delete_messages(DialogId dialog_id, const vector &input_message_ids, bool revoke, @@ -16583,8 +16588,9 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo return false; } - // TODO use const from the config - if (has_edit_time_limit && G()->unix_time_cached() - m->date >= 2 * 86400 + (is_editing ? 300 : 0)) { + const int32 DEFAULT_EDIT_TIME_LIMIT = 2 * 86400; + int32 edit_time_limit = G()->shared_config().get_option_integer("edit_time_limit", DEFAULT_EDIT_TIME_LIMIT); + if (has_edit_time_limit && G()->unix_time_cached() - m->date >= edit_time_limit + (is_editing ? 300 : 0)) { return false; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 1bc6c4c7..cc3da61d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3897,6 +3897,13 @@ void Td::on_result(NetQueryPtr query) { handler->on_result(std::move(query)); } +bool Td::is_internal_config_option(Slice name) { + return name == "call_ring_timeout_ms" || name == "call_receive_timeout_ms" || name == "channels_read_media_period" || + name == "edit_time_limit" || name == "revoke_pm_inbox" || name == "revoke_time_limit" || + name == "revoke_pm_time_limit" || name == "rating_e_decay" || name == "saved_animations_limit" || + name == "auth"; +} + void Td::on_config_option_updated(const string &name) { if (close_flag_) { return; @@ -3918,8 +3925,7 @@ void Td::on_config_option_updated(const string &name) { send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer); } else if (name == "rating_e_decay") { return send_closure(top_dialog_manager_, &TopDialogManager::update_rating_e_decay); - } else if (name == "call_ring_timeout_ms" || name == "call_receive_timeout_ms" || - name == "channels_read_media_period") { + } else if (is_internal_config_option(name)) { return; } send_closure(actor_id(this), &Td::send_update, @@ -4112,12 +4118,9 @@ void Td::clear() { Timer timer; if (destroy_flag_) { for (auto &option : G()->shared_config().get_options()) { - if (option.first == "rating_e_decay" || option.first == "saved_animations_limit" || - option.first == "call_receive_timeout_ms" || option.first == "call_ring_timeout_ms" || - option.first == "channels_read_media_period" || option.first == "auth") { - continue; + if (!is_internal_config_option(option.first)) { + send_update(make_tl_object(option.first, make_tl_object())); } - send_update(make_tl_object(option.first, make_tl_object())); } } LOG(DEBUG) << "Options was cleared " << timer; diff --git a/td/telegram/Td.h b/td/telegram/Td.h index f1b7386e..c227dcc7 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -255,6 +255,8 @@ class Td final : public NetQueryCallback { void clear_handlers(); // void destroy_handler(ResultHandler *handler); + static bool is_internal_config_option(Slice name); + void on_config_option_updated(const string &name); static tl_object_ptr get_connection_state_object(StateManager::State state);