2021-12-15 23:09:59 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
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)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2021-12-15 23:45:43 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2021-12-15 23:09:59 +01:00
|
|
|
|
2022-08-18 17:52:59 +02:00
|
|
|
#include <atomic>
|
2022-08-18 13:54:57 +02:00
|
|
|
#include <memory>
|
2022-08-18 18:54:04 +02:00
|
|
|
#include <utility>
|
2022-08-18 13:54:57 +02:00
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
namespace td {
|
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
class KeyValueSyncInterface;
|
2021-12-15 23:09:59 +01:00
|
|
|
class Td;
|
2022-08-18 13:54:57 +02:00
|
|
|
class TsSeqKeyValue;
|
2021-12-15 23:09:59 +01:00
|
|
|
|
2022-08-18 17:52:59 +02:00
|
|
|
class OptionManager {
|
2021-12-15 23:09:59 +01:00
|
|
|
public:
|
2022-08-18 17:52:59 +02:00
|
|
|
explicit OptionManager(Td *td);
|
2021-12-15 23:09:59 +01:00
|
|
|
OptionManager(const OptionManager &) = delete;
|
|
|
|
OptionManager &operator=(const OptionManager &) = delete;
|
|
|
|
OptionManager(OptionManager &&) = delete;
|
|
|
|
OptionManager &operator=(OptionManager &&) = delete;
|
2022-08-18 17:52:59 +02:00
|
|
|
~OptionManager();
|
2021-12-15 23:09:59 +01:00
|
|
|
|
2023-12-08 10:57:13 +01:00
|
|
|
void update_premium_options();
|
|
|
|
|
2022-08-18 18:12:15 +02:00
|
|
|
void on_td_inited();
|
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
void set_option_boolean(Slice name, bool value);
|
|
|
|
|
|
|
|
void set_option_empty(Slice name);
|
|
|
|
|
|
|
|
void set_option_integer(Slice name, int64 value);
|
|
|
|
|
|
|
|
void set_option_string(Slice name, Slice value);
|
|
|
|
|
|
|
|
bool have_option(Slice name) const;
|
|
|
|
|
|
|
|
bool get_option_boolean(Slice name, bool default_value = false) const;
|
2021-12-16 13:18:51 +01:00
|
|
|
|
2022-08-18 13:54:57 +02:00
|
|
|
int64 get_option_integer(Slice name, int64 default_value = 0) const;
|
|
|
|
|
|
|
|
string get_option_string(Slice name, string default_value = "") const;
|
|
|
|
|
|
|
|
void on_update_server_time_difference();
|
2021-12-15 23:45:43 +01:00
|
|
|
|
2021-12-16 10:07:32 +01:00
|
|
|
void get_option(const string &name, Promise<td_api::object_ptr<td_api::OptionValue>> &&promise);
|
|
|
|
|
2021-12-16 11:13:14 +01:00
|
|
|
void set_option(const string &name, td_api::object_ptr<td_api::OptionValue> &&value, Promise<Unit> &&promise);
|
|
|
|
|
2022-07-11 12:33:56 +02:00
|
|
|
static bool is_synchronous_option(Slice name);
|
|
|
|
|
2022-07-11 14:36:29 +02:00
|
|
|
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);
|
2022-07-11 12:33:56 +02:00
|
|
|
|
2021-12-16 10:16:09 +01:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
2021-12-15 23:45:43 +01:00
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
private:
|
2022-08-18 13:54:57 +02:00
|
|
|
void set_option(Slice name, Slice value);
|
|
|
|
|
|
|
|
void on_option_updated(Slice name);
|
|
|
|
|
|
|
|
string get_option(Slice name) const;
|
|
|
|
|
2021-12-15 23:45:43 +01:00
|
|
|
static bool is_internal_option(Slice name);
|
|
|
|
|
2023-01-17 12:24:18 +01:00
|
|
|
td_api::object_ptr<td_api::Update> get_internal_option_update(Slice name) const;
|
|
|
|
|
2022-07-11 14:36:29 +02:00
|
|
|
static const vector<Slice> &get_synchronous_options();
|
|
|
|
|
2021-12-16 13:18:51 +01:00
|
|
|
static td_api::object_ptr<td_api::OptionValue> get_unix_time_option_value_object();
|
|
|
|
|
2021-12-16 20:56:19 +01:00
|
|
|
static td_api::object_ptr<td_api::OptionValue> get_option_value_object(Slice value);
|
|
|
|
|
2021-12-16 13:18:51 +01:00
|
|
|
void send_unix_time_update();
|
|
|
|
|
2021-12-15 23:09:59 +01:00
|
|
|
Td *td_;
|
2022-08-18 18:12:15 +02:00
|
|
|
bool is_td_inited_ = false;
|
2022-08-18 18:54:04 +02:00
|
|
|
vector<std::pair<string, Promise<td_api::object_ptr<td_api::OptionValue>>>> pending_get_options_;
|
2021-12-16 13:18:51 +01:00
|
|
|
|
2022-10-04 20:08:07 +02:00
|
|
|
int32 current_scheduler_id_ = -1;
|
2022-08-18 13:54:57 +02:00
|
|
|
unique_ptr<TsSeqKeyValue> options_;
|
|
|
|
std::shared_ptr<KeyValueSyncInterface> option_pmc_;
|
|
|
|
|
2022-08-18 17:52:59 +02:00
|
|
|
std::atomic<double> last_sent_server_time_difference_{1e100};
|
2021-12-15 23:09:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|