Add and use everywhere OptionsManager::get_synchronous_options().
This commit is contained in:
parent
ee7011538a
commit
e44418f2b3
@ -29,6 +29,7 @@
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/TopDialogManager.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
@ -211,8 +212,13 @@ bool OptionManager::is_internal_option(Slice name) {
|
||||
}
|
||||
}
|
||||
|
||||
const vector<Slice> &OptionManager::get_synchronous_options() {
|
||||
static const vector<Slice> options{"version", "commit_hash"};
|
||||
return options;
|
||||
}
|
||||
|
||||
bool OptionManager::is_synchronous_option(Slice name) {
|
||||
return name == "version" || name == "commit_hash";
|
||||
return td::contains(get_synchronous_options(), name);
|
||||
}
|
||||
|
||||
void OptionManager::on_option_updated(const string &name) {
|
||||
@ -433,7 +439,8 @@ void OptionManager::get_option(const string &name, Promise<td_api::object_ptr<td
|
||||
wrap_promise().set_value(Unit());
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::OptionValue> OptionManager::get_option_synchronously(const string &name) {
|
||||
td_api::object_ptr<td_api::OptionValue> OptionManager::get_option_synchronously(Slice name) {
|
||||
CHECK(!name.empty());
|
||||
switch (name[0]) {
|
||||
case 'c':
|
||||
if (name == "commit_hash") {
|
||||
@ -775,9 +782,15 @@ td_api::object_ptr<td_api::OptionValue> OptionManager::get_option_value_object(S
|
||||
return td_api::make_object<td_api::optionValueString>(value.str());
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
void OptionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||
updates.push_back(td_api::make_object<td_api::updateOption>("version", get_option_synchronously("version")));
|
||||
updates.push_back(td_api::make_object<td_api::updateOption>("commit_hash", get_option_synchronously("commit_hash")));
|
||||
get_common_state(updates);
|
||||
|
||||
updates.push_back(td_api::make_object<td_api::updateOption>(
|
||||
"online", td_api::make_object<td_api::optionValueBoolean>(td_->is_online())));
|
||||
|
@ -40,7 +40,9 @@ class OptionManager final : public Actor {
|
||||
|
||||
static bool is_synchronous_option(Slice name);
|
||||
|
||||
static td_api::object_ptr<td_api::OptionValue> get_option_synchronously(const string &name);
|
||||
static td_api::object_ptr<td_api::OptionValue> get_option_synchronously(Slice name);
|
||||
|
||||
static void get_common_state(vector<td_api::object_ptr<td_api::Update>> &updates);
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
@ -49,6 +51,8 @@ class OptionManager final : public Actor {
|
||||
|
||||
static bool is_internal_option(Slice name);
|
||||
|
||||
static const vector<Slice> &get_synchronous_options();
|
||||
|
||||
static td_api::object_ptr<td_api::OptionValue> get_unix_time_option_value_object();
|
||||
|
||||
static td_api::object_ptr<td_api::OptionValue> get_option_value_object(Slice value);
|
||||
|
@ -3010,6 +3010,14 @@ td_api::object_ptr<td_api::AuthorizationState> Td::get_fake_authorization_state_
|
||||
}
|
||||
}
|
||||
|
||||
vector<td_api::object_ptr<td_api::Update>> Td::get_fake_current_state() const {
|
||||
CHECK(state_ != State::Run);
|
||||
vector<td_api::object_ptr<td_api::Update>> updates;
|
||||
OptionManager::get_common_state(updates);
|
||||
updates.push_back(td_api::make_object<td_api::updateAuthorizationState>(get_fake_authorization_state_object()));
|
||||
return updates;
|
||||
}
|
||||
|
||||
DbKey Td::as_db_key(string key) {
|
||||
// Database will still be effectively not encrypted, but
|
||||
// 1. SQLite database will be protected from corruption, because that's how sqlcipher works
|
||||
@ -3057,16 +3065,9 @@ void Td::run_request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
||||
case td_api::getAuthorizationState::ID:
|
||||
// send response synchronously to prevent "Request aborted"
|
||||
return send_result(id, get_fake_authorization_state_object());
|
||||
case td_api::getCurrentState::ID: {
|
||||
vector<td_api::object_ptr<td_api::Update>> updates;
|
||||
updates.push_back(
|
||||
td_api::make_object<td_api::updateOption>("version", OptionManager::get_option_synchronously("version")));
|
||||
updates.push_back(td_api::make_object<td_api::updateOption>(
|
||||
"commit_hash", OptionManager::get_option_synchronously("commit_hash")));
|
||||
updates.push_back(td_api::make_object<td_api::updateAuthorizationState>(get_fake_authorization_state_object()));
|
||||
case td_api::getCurrentState::ID:
|
||||
// send response synchronously to prevent "Request aborted"
|
||||
return send_result(id, td_api::make_object<td_api::updates>(std::move(updates)));
|
||||
}
|
||||
return send_result(id, td_api::make_object<td_api::updates>(get_fake_current_state()));
|
||||
case td_api::close::ID:
|
||||
// need to send response before actual closing
|
||||
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
|
||||
@ -3279,11 +3280,9 @@ void Td::start_up() {
|
||||
alarm_timeout_.set_callback_data(static_cast<void *>(this));
|
||||
|
||||
CHECK(state_ == State::WaitParameters);
|
||||
send_update(td_api::make_object<td_api::updateOption>("version", OptionManager::get_option_synchronously("version")));
|
||||
send_update(
|
||||
td_api::make_object<td_api::updateOption>("commit_hash", OptionManager::get_option_synchronously("commit_hash")));
|
||||
send_update(td_api::make_object<td_api::updateAuthorizationState>(
|
||||
td_api::make_object<td_api::authorizationStateWaitTdlibParameters>()));
|
||||
for (auto &update : get_fake_current_state()) {
|
||||
send_update(std::move(update));
|
||||
}
|
||||
}
|
||||
|
||||
void Td::tear_down() {
|
||||
|
@ -328,6 +328,8 @@ class Td final : public Actor {
|
||||
|
||||
td_api::object_ptr<td_api::AuthorizationState> get_fake_authorization_state_object() const;
|
||||
|
||||
vector<td_api::object_ptr<td_api::Update>> get_fake_current_state() const;
|
||||
|
||||
static void on_alarm_timeout_callback(void *td_ptr, int64 alarm_id);
|
||||
void on_alarm_timeout(int64 alarm_id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user