2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +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/ConfigManager.h"
|
|
|
|
|
2019-12-19 21:00:28 +01:00
|
|
|
#include "td/telegram/AuthManager.h"
|
2021-09-16 17:23:10 +02:00
|
|
|
#include "td/telegram/ConnectionState.h"
|
2023-06-27 16:26:17 +02:00
|
|
|
#include "td/telegram/ContactsManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/Global.h"
|
2019-12-19 02:23:14 +01:00
|
|
|
#include "td/telegram/JsonValue.h"
|
2021-05-25 01:39:29 +02:00
|
|
|
#include "td/telegram/LinkManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/logevent/LogEvent.h"
|
2022-08-22 14:44:38 +02:00
|
|
|
#include "td/telegram/MessageReaction.h"
|
2022-11-29 21:42:29 +01:00
|
|
|
#include "td/telegram/misc.h"
|
2019-07-23 01:14:34 +02:00
|
|
|
#include "td/telegram/net/AuthDataShared.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/ConnectionCreator.h"
|
2018-06-26 01:43:11 +02:00
|
|
|
#include "td/telegram/net/DcId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/DcOptions.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
|
|
|
#include "td/telegram/net/NetQueryDispatcher.h"
|
2018-06-26 01:43:11 +02:00
|
|
|
#include "td/telegram/net/NetType.h"
|
|
|
|
#include "td/telegram/net/PublicRsaKeyShared.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/Session.h"
|
2022-05-24 00:21:03 +02:00
|
|
|
#include "td/telegram/Premium.h"
|
2018-10-28 18:30:47 +01:00
|
|
|
#include "td/telegram/StateManager.h"
|
2019-12-19 21:00:28 +01:00
|
|
|
#include "td/telegram/Td.h"
|
2019-01-06 20:59:17 +01:00
|
|
|
#include "td/telegram/TdDb.h"
|
2019-01-31 03:05:40 +01:00
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/mtproto/AuthData.h"
|
|
|
|
#include "td/mtproto/AuthKey.h"
|
|
|
|
#include "td/mtproto/RawConnection.h"
|
2020-05-17 16:07:16 +02:00
|
|
|
#include "td/mtproto/RSA.h"
|
2019-07-23 00:50:12 +02:00
|
|
|
#include "td/mtproto/TransportType.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-01-08 15:42:55 +01:00
|
|
|
#if !TD_EMSCRIPTEN //FIXME
|
2022-11-11 12:23:43 +01:00
|
|
|
#include "td/net/SslCtx.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/net/Wget.h"
|
|
|
|
#endif
|
|
|
|
|
2021-06-23 02:22:23 +02:00
|
|
|
#include "td/net/HttpQuery.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2021-01-01 13:59:53 +01:00
|
|
|
#include "td/utils/algorithm.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/base64.h"
|
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/crypto.h"
|
2021-10-05 22:20:49 +02:00
|
|
|
#include "td/utils/emoji.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/format.h"
|
|
|
|
#include "td/utils/JsonBuilder.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/misc.h"
|
2019-07-23 00:50:12 +02:00
|
|
|
#include "td/utils/Parser.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/port/Clocks.h"
|
|
|
|
#include "td/utils/Random.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Time.h"
|
2018-06-05 19:44:41 +02:00
|
|
|
#include "td/utils/tl_helpers.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/tl_parsers.h"
|
2018-12-19 22:18:53 +01:00
|
|
|
#include "td/utils/UInt.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2023-05-07 00:43:00 +02:00
|
|
|
#include <algorithm>
|
2021-02-25 13:56:26 +01:00
|
|
|
#include <functional>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2018-12-26 21:58:18 +01:00
|
|
|
int VERBOSITY_NAME(config_recoverer) = VERBOSITY_NAME(INFO);
|
2019-07-11 22:32:45 +02:00
|
|
|
|
|
|
|
Result<int32> HttpDate::to_unix_time(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second) {
|
2019-07-11 13:25:20 +02:00
|
|
|
if (year < 1970 || year > 2037) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid year");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
if (month < 1 || month > 12) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid month");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
if (day < 1 || day > days_in_month(year, month)) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid day");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
if (hour < 0 || hour >= 24) {
|
|
|
|
return Status::Error("Invalid hour");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
if (minute < 0 || minute >= 60) {
|
|
|
|
return Status::Error("Invalid minute");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
if (second < 0 || second > 60) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid second");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
|
|
|
|
int32 res = 0;
|
|
|
|
for (int32 y = 1970; y < year; y++) {
|
2019-07-11 13:25:20 +02:00
|
|
|
res += (is_leap(y) + 365) * seconds_in_day();
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
for (int32 m = 1; m < month; m++) {
|
2019-07-11 13:25:20 +02:00
|
|
|
res += days_in_month(year, m) * seconds_in_day();
|
|
|
|
}
|
|
|
|
res += (day - 1) * seconds_in_day();
|
|
|
|
res += hour * 60 * 60;
|
|
|
|
res += minute * 60;
|
|
|
|
res += second;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-02-22 16:25:49 +01:00
|
|
|
Result<int32> HttpDate::parse_http_date(string slice) {
|
2019-07-11 22:32:45 +02:00
|
|
|
Parser p(slice);
|
2019-07-11 13:25:20 +02:00
|
|
|
p.read_till(','); // ignore week day
|
|
|
|
p.skip(',');
|
|
|
|
p.skip_whitespaces();
|
2019-07-11 22:32:45 +02:00
|
|
|
p.skip_nofail('0');
|
2019-07-11 13:25:20 +02:00
|
|
|
TRY_RESULT(day, to_integer_safe<int32>(p.read_word()));
|
|
|
|
auto month_name = p.read_word();
|
|
|
|
to_lower_inplace(month_name);
|
|
|
|
TRY_RESULT(year, to_integer_safe<int32>(p.read_word()));
|
|
|
|
p.skip_whitespaces();
|
|
|
|
p.skip_nofail('0');
|
|
|
|
TRY_RESULT(hour, to_integer_safe<int32>(p.read_till(':')));
|
|
|
|
p.skip(':');
|
|
|
|
p.skip_nofail('0');
|
|
|
|
TRY_RESULT(minute, to_integer_safe<int32>(p.read_till(':')));
|
|
|
|
p.skip(':');
|
|
|
|
p.skip_nofail('0');
|
|
|
|
TRY_RESULT(second, to_integer_safe<int32>(p.read_word()));
|
|
|
|
auto gmt = p.read_word();
|
|
|
|
TRY_STATUS(std::move(p.status()));
|
|
|
|
if (gmt != "GMT") {
|
2019-08-26 03:53:22 +02:00
|
|
|
return Status::Error("Timezone must be GMT");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
|
2019-07-11 22:32:45 +02:00
|
|
|
static Slice month_names[12] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
|
2019-07-11 13:25:20 +02:00
|
|
|
|
|
|
|
int month = 0;
|
|
|
|
|
|
|
|
for (int m = 1; m <= 12; m++) {
|
|
|
|
if (month_names[m - 1] == month_name) {
|
|
|
|
month = m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (month == 0) {
|
|
|
|
return Status::Error("Unknown month name");
|
|
|
|
}
|
|
|
|
|
|
|
|
return HttpDate::to_unix_time(year, month, day, hour, minute, second);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Result<SimpleConfig> decode_config(Slice input) {
|
2021-07-05 20:04:23 +02:00
|
|
|
static auto rsa = mtproto::RSA::from_pem_public_key(
|
2018-12-31 20:04:05 +01:00
|
|
|
"-----BEGIN RSA PUBLIC KEY-----\n"
|
|
|
|
"MIIBCgKCAQEAyr+18Rex2ohtVy8sroGP\n"
|
|
|
|
"BwXD3DOoKCSpjDqYoXgCqB7ioln4eDCFfOBUlfXUEvM/fnKCpF46VkAftlb4VuPD\n"
|
|
|
|
"eQSS/ZxZYEGqHaywlroVnXHIjgqoxiAd192xRGreuXIaUKmkwlM9JID9WS2jUsTp\n"
|
|
|
|
"zQ91L8MEPLJ/4zrBwZua8W5fECwCCh2c9G5IzzBm+otMS/YKwmR1olzRCyEkyAEj\n"
|
|
|
|
"XWqBI9Ftv5eG8m0VkBzOG655WIYdyV0HfDK/NWcvGqa0w/nriMD6mDjKOryamw0O\n"
|
|
|
|
"P9QuYgMN0C9xMW9y8SmP4h92OAWodTYgY1hZCxdv6cs5UnW9+PWvS+WIbkh+GaWY\n"
|
|
|
|
"xwIDAQAB\n"
|
|
|
|
"-----END RSA PUBLIC KEY-----\n")
|
|
|
|
.move_as_ok();
|
|
|
|
|
|
|
|
if (input.size() < 344 || input.size() > 1024) {
|
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("length", input.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data_base64 = base64_filter(input);
|
|
|
|
if (data_base64.size() != 344) {
|
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("length", data_base64.size()) << " after base64_filter");
|
|
|
|
}
|
|
|
|
TRY_RESULT(data_rsa, base64_decode(data_base64));
|
|
|
|
if (data_rsa.size() != 256) {
|
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("length", data_rsa.size()) << " after base64_decode");
|
|
|
|
}
|
|
|
|
|
|
|
|
MutableSlice data_rsa_slice(data_rsa);
|
2020-03-10 16:27:43 +01:00
|
|
|
rsa.decrypt_signature(data_rsa_slice, data_rsa_slice);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
MutableSlice data_cbc = data_rsa_slice.substr(32);
|
|
|
|
UInt256 key;
|
|
|
|
UInt128 iv;
|
2023-02-02 15:40:47 +01:00
|
|
|
as_mutable_slice(key).copy_from(data_rsa_slice.substr(0, 32));
|
|
|
|
as_mutable_slice(iv).copy_from(data_rsa_slice.substr(16, 16));
|
|
|
|
aes_cbc_decrypt(as_slice(key), as_mutable_slice(iv), data_cbc, data_cbc);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
CHECK(data_cbc.size() == 224);
|
|
|
|
string hash(32, ' ');
|
|
|
|
sha256(data_cbc.substr(0, 208), MutableSlice(hash));
|
|
|
|
if (data_cbc.substr(208) != Slice(hash).substr(0, 16)) {
|
2019-08-26 03:53:22 +02:00
|
|
|
return Status::Error("SHA256 mismatch");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TlParser len_parser{data_cbc};
|
|
|
|
int len = len_parser.fetch_int();
|
2019-07-11 02:12:27 +02:00
|
|
|
if (len < 8 || len > 208) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("data length", len) << " after aes_cbc_decrypt");
|
|
|
|
}
|
|
|
|
int constructor_id = len_parser.fetch_int();
|
|
|
|
if (constructor_id != telegram_api::help_configSimple::ID) {
|
|
|
|
return Status::Error(PSLICE() << "Wrong " << tag("constructor", format::as_hex(constructor_id)));
|
|
|
|
}
|
2019-07-11 02:12:27 +02:00
|
|
|
BufferSlice raw_config(data_cbc.substr(8, len - 8));
|
2018-12-31 20:04:05 +01:00
|
|
|
TlBufferParser parser{&raw_config};
|
|
|
|
auto config = telegram_api::help_configSimple::fetch(parser);
|
2019-07-11 02:12:27 +02:00
|
|
|
parser.fetch_end();
|
2018-12-31 20:04:05 +01:00
|
|
|
TRY_STATUS(parser.get_status());
|
|
|
|
return std::move(config);
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
static ActorOwn<> get_simple_config_impl(Promise<SimpleConfigResult> promise, int32 scheduler_id, string url,
|
2019-11-19 16:12:51 +01:00
|
|
|
string host, std::vector<std::pair<string, string>> headers, bool prefer_ipv6,
|
2020-01-08 15:42:55 +01:00
|
|
|
std::function<Result<string>(HttpQuery &)> get_config,
|
|
|
|
string content = string(), string content_type = string()) {
|
2018-03-12 19:04:03 +01:00
|
|
|
VLOG(config_recoverer) << "Request simple config from " << url;
|
2018-12-31 20:04:05 +01:00
|
|
|
#if TD_EMSCRIPTEN // FIXME
|
|
|
|
return ActorOwn<>();
|
|
|
|
#else
|
2018-07-01 03:45:25 +02:00
|
|
|
const int timeout = 10;
|
|
|
|
const int ttl = 3;
|
2019-11-19 16:12:51 +01:00
|
|
|
headers.emplace_back("Host", std::move(host));
|
|
|
|
headers.emplace_back("User-Agent",
|
|
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
|
|
"Chrome/77.0.3865.90 Safari/537.36");
|
2018-12-31 20:04:05 +01:00
|
|
|
return ActorOwn<>(create_actor_on_scheduler<Wget>(
|
|
|
|
"Wget", scheduler_id,
|
2019-11-19 15:58:24 +01:00
|
|
|
PromiseCreator::lambda([get_config = std::move(get_config),
|
|
|
|
promise = std::move(promise)](Result<unique_ptr<HttpQuery>> r_query) mutable {
|
2019-07-11 13:25:20 +02:00
|
|
|
promise.set_result([&]() -> Result<SimpleConfigResult> {
|
2018-12-31 20:04:05 +01:00
|
|
|
TRY_RESULT(http_query, std::move(r_query));
|
2019-07-11 13:25:20 +02:00
|
|
|
SimpleConfigResult res;
|
2019-07-11 22:32:45 +02:00
|
|
|
res.r_http_date = HttpDate::parse_http_date(http_query->get_header("date").str());
|
2019-11-19 15:58:24 +01:00
|
|
|
auto r_config = get_config(*http_query);
|
|
|
|
if (r_config.is_error()) {
|
|
|
|
res.r_config = r_config.move_as_error();
|
|
|
|
} else {
|
|
|
|
res.r_config = decode_config(r_config.ok());
|
|
|
|
}
|
2019-07-22 06:05:50 +02:00
|
|
|
return std::move(res);
|
2018-12-31 20:04:05 +01:00
|
|
|
}());
|
|
|
|
}),
|
2022-11-11 12:23:43 +01:00
|
|
|
std::move(url), std::move(headers), timeout, ttl, prefer_ipv6, SslCtx::VerifyPeer::Off, std::move(content),
|
2019-11-19 16:12:51 +01:00
|
|
|
std::move(content_type)));
|
2018-12-31 20:04:05 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-18 20:45:29 +02:00
|
|
|
ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, bool prefer_ipv6, Slice domain_name,
|
|
|
|
bool is_test, int32 scheduler_id) {
|
2018-05-24 17:09:27 +02:00
|
|
|
string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod")
|
|
|
|
<< "v2/config.txt";
|
2019-11-19 16:12:51 +01:00
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "tcdnb.azureedge.net", {},
|
2020-01-07 16:16:57 +01:00
|
|
|
prefer_ipv6,
|
2020-01-08 15:42:55 +01:00
|
|
|
[](HttpQuery &http_query) -> Result<string> { return http_query.content_.str(); });
|
2018-03-12 19:04:03 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 21:20:15 +02:00
|
|
|
static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<SimpleConfigResult> promise,
|
2022-08-18 20:45:29 +02:00
|
|
|
bool prefer_ipv6, Slice domain_name, bool is_test, int32 scheduler_id) {
|
|
|
|
if (domain_name.empty()) {
|
|
|
|
domain_name = is_test ? Slice("tapv3.stel.com") : Slice("apv3.stel.com");
|
2018-06-30 15:35:37 +02:00
|
|
|
}
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2022-02-10 21:23:10 +01:00
|
|
|
auto get_data = [](JsonValue &answer) -> Result<string> {
|
|
|
|
auto &answer_array = answer.get_array();
|
|
|
|
vector<string> parts;
|
|
|
|
for (auto &answer_part : answer_array) {
|
|
|
|
if (answer_part.type() != JsonValue::Type::Object) {
|
|
|
|
return Status::Error("Expected JSON object");
|
|
|
|
}
|
|
|
|
auto &data_object = answer_part.get_object();
|
|
|
|
TRY_RESULT(part, get_json_object_string_field(data_object, "data", false));
|
|
|
|
parts.push_back(std::move(part));
|
2019-11-19 16:12:51 +01:00
|
|
|
}
|
2022-02-10 21:23:10 +01:00
|
|
|
if (parts.size() != 2) {
|
|
|
|
return Status::Error("Expected data in two parts");
|
|
|
|
}
|
|
|
|
string data;
|
|
|
|
if (parts[0].size() < parts[1].size()) {
|
|
|
|
data = parts[1] + parts[0];
|
|
|
|
} else {
|
|
|
|
data = parts[0] + parts[1];
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
if (!http_query.get_arg("Answer").empty()) {
|
|
|
|
VLOG(config_recoverer) << "Receive DNS response " << http_query.get_arg("Answer");
|
|
|
|
TRY_RESULT(answer, json_decode(http_query.get_arg("Answer")));
|
|
|
|
if (answer.type() != JsonValue::Type::Array) {
|
|
|
|
return Status::Error("Expected JSON array");
|
|
|
|
}
|
|
|
|
return get_data(answer);
|
2019-11-19 16:12:51 +01:00
|
|
|
} else {
|
2022-02-10 21:23:10 +01:00
|
|
|
VLOG(config_recoverer) << "Receive DNS response " << http_query.content_;
|
|
|
|
TRY_RESULT(json, json_decode(http_query.content_));
|
|
|
|
if (json.type() != JsonValue::Type::Object) {
|
|
|
|
return Status::Error("Expected JSON object");
|
|
|
|
}
|
|
|
|
auto &answer_object = json.get_object();
|
|
|
|
TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false));
|
|
|
|
return get_data(answer);
|
2019-11-19 16:12:51 +01:00
|
|
|
}
|
|
|
|
};
|
2022-08-18 20:45:29 +02:00
|
|
|
return get_simple_config_impl(
|
|
|
|
std::move(promise), scheduler_id,
|
|
|
|
PSTRING() << "https://" << address << "?name=" << url_encode(domain_name) << "&type=TXT", host.str(),
|
|
|
|
{{"Accept", "application/dns-json"}}, prefer_ipv6, std::move(get_config));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-08-18 20:45:29 +02:00
|
|
|
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, bool prefer_ipv6, Slice domain_name,
|
|
|
|
bool is_test, int32 scheduler_id) {
|
|
|
|
return get_simple_config_dns("dns.google/resolve", "dns.google", std::move(promise), prefer_ipv6, domain_name,
|
|
|
|
is_test, scheduler_id);
|
2019-10-03 21:20:15 +02:00
|
|
|
}
|
|
|
|
|
2022-08-18 20:45:29 +02:00
|
|
|
ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, bool prefer_ipv6, Slice domain_name,
|
|
|
|
bool is_test, int32 scheduler_id) {
|
2019-10-03 21:20:15 +02:00
|
|
|
return get_simple_config_dns("mozilla.cloudflare-dns.com/dns-query", "mozilla.cloudflare-dns.com", std::move(promise),
|
2022-08-18 20:45:29 +02:00
|
|
|
prefer_ipv6, domain_name, is_test, scheduler_id);
|
2019-10-03 21:20:15 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 15:58:24 +01:00
|
|
|
static string generate_firebase_remote_config_payload() {
|
|
|
|
unsigned char buf[17];
|
|
|
|
Random::secure_bytes(buf, sizeof(buf));
|
|
|
|
buf[0] = static_cast<unsigned char>((buf[0] & 0xF0) | 0x07);
|
|
|
|
auto app_instance_id = base64url_encode(Slice(buf, sizeof(buf)));
|
|
|
|
app_instance_id.resize(22);
|
|
|
|
return PSTRING() << "{\"app_id\":\"1:560508485281:web:4ee13a6af4e84d49e67ae0\",\"app_instance_id\":\""
|
|
|
|
<< app_instance_id << "\"}";
|
|
|
|
}
|
|
|
|
|
2022-08-18 20:45:29 +02:00
|
|
|
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise, bool prefer_ipv6,
|
|
|
|
Slice domain_name, bool is_test, int32 scheduler_id) {
|
2019-11-19 15:58:24 +01:00
|
|
|
if (is_test) {
|
|
|
|
promise.set_error(Status::Error(400, "Test config is not supported"));
|
|
|
|
return ActorOwn<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const string payload = generate_firebase_remote_config_payload();
|
|
|
|
string url =
|
|
|
|
"https://firebaseremoteconfig.googleapis.com/v1/projects/peak-vista-421/namespaces/"
|
|
|
|
"firebase:fetch?key=AIzaSyC2-kAkpDsroixRXw-sTw-Wfqo4NxjMwwM";
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2019-11-19 15:58:24 +01:00
|
|
|
TRY_RESULT(json, json_decode(http_query.get_arg("entries")));
|
|
|
|
if (json.type() != JsonValue::Type::Object) {
|
2019-11-19 17:26:39 +01:00
|
|
|
return Status::Error("Expected JSON object");
|
2019-11-19 15:58:24 +01:00
|
|
|
}
|
|
|
|
auto &entries_object = json.get_object();
|
|
|
|
TRY_RESULT(config, get_json_object_string_field(entries_object, "ipconfigv3", false));
|
|
|
|
return std::move(config);
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "firebaseremoteconfig.googleapis.com",
|
2019-11-19 16:12:51 +01:00
|
|
|
{}, prefer_ipv6, std::move(get_config), payload, "application/json");
|
2019-11-19 15:58:24 +01:00
|
|
|
}
|
|
|
|
|
2022-08-18 20:45:29 +02:00
|
|
|
ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, bool prefer_ipv6, Slice domain_name,
|
2019-11-19 17:01:12 +01:00
|
|
|
bool is_test, int32 scheduler_id) {
|
|
|
|
if (is_test) {
|
|
|
|
promise.set_error(Status::Error(400, "Test config is not supported"));
|
|
|
|
return ActorOwn<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
string url = "https://reserve-5a846.firebaseio.com/ipconfigv3.json";
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2019-11-19 17:01:12 +01:00
|
|
|
return http_query.get_arg("content").str();
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "reserve-5a846.firebaseio.com", {},
|
|
|
|
prefer_ipv6, std::move(get_config));
|
|
|
|
}
|
|
|
|
|
2022-08-18 20:45:29 +02:00
|
|
|
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, bool prefer_ipv6,
|
|
|
|
Slice domain_name, bool is_test, int32 scheduler_id) {
|
2019-11-19 17:26:39 +01:00
|
|
|
if (is_test) {
|
|
|
|
promise.set_error(Status::Error(400, "Test config is not supported"));
|
|
|
|
return ActorOwn<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
string url = "https://www.google.com/v1/projects/reserve-5a846/databases/(default)/documents/ipconfig/v3";
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2019-11-19 17:26:39 +01:00
|
|
|
TRY_RESULT(json, json_decode(http_query.get_arg("fields")));
|
|
|
|
if (json.type() != JsonValue::Type::Object) {
|
|
|
|
return Status::Error("Expected JSON object");
|
|
|
|
}
|
|
|
|
TRY_RESULT(data, get_json_object_field(json.get_object(), "data", JsonValue::Type::Object, false));
|
|
|
|
TRY_RESULT(config, get_json_object_string_field(data.get_object(), "stringValue", false));
|
|
|
|
return std::move(config);
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "firestore.googleapis.com", {},
|
|
|
|
prefer_ipv6, std::move(get_config));
|
|
|
|
}
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
static ActorOwn<> get_full_config(DcOption option, Promise<tl_object_ptr<telegram_api::config>> promise,
|
|
|
|
ActorShared<> parent) {
|
2021-07-04 04:58:54 +02:00
|
|
|
class SessionCallback final : public Session::Callback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2019-07-11 13:25:20 +02:00
|
|
|
SessionCallback(ActorShared<> parent, DcOption option) : parent_(std::move(parent)), option_(std::move(option)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
void on_failed() final {
|
|
|
|
}
|
|
|
|
void on_closed() final {
|
|
|
|
}
|
2019-05-06 20:53:39 +02:00
|
|
|
void request_raw_connection(unique_ptr<mtproto::AuthData> auth_data,
|
|
|
|
Promise<unique_ptr<mtproto::RawConnection>> promise) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
request_raw_connection_cnt_++;
|
2019-07-11 13:25:20 +02:00
|
|
|
VLOG(config_recoverer) << "Request full config from " << option_.get_ip_address()
|
|
|
|
<< ", try = " << request_raw_connection_cnt_;
|
2018-05-18 13:38:49 +02:00
|
|
|
if (request_raw_connection_cnt_ <= 2) {
|
2019-07-11 13:25:20 +02:00
|
|
|
send_closure(G()->connection_creator(), &ConnectionCreator::request_raw_connection_by_ip,
|
|
|
|
option_.get_ip_address(),
|
|
|
|
mtproto::TransportType{mtproto::TransportType::ObfuscatedTcp,
|
|
|
|
narrow_cast<int16>(option_.get_dc_id().get_raw_id()), option_.get_secret()},
|
|
|
|
std::move(promise));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2018-02-07 21:48:40 +01:00
|
|
|
// Delay all queries except first forever
|
2018-12-31 20:04:05 +01:00
|
|
|
delay_forever_.push_back(std::move(promise));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key) final {
|
2018-02-07 21:48:40 +01:00
|
|
|
// nop
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-09-10 15:45:39 +02:00
|
|
|
void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts) final {
|
|
|
|
// nop
|
|
|
|
}
|
2023-01-25 15:48:04 +01:00
|
|
|
void on_update(BufferSlice &&update, uint64 auth_key_id) final {
|
2021-09-10 16:32:39 +02:00
|
|
|
// nop
|
|
|
|
}
|
2019-03-15 10:00:18 +01:00
|
|
|
void on_result(NetQueryPtr net_query) final {
|
|
|
|
G()->net_query_dispatcher().dispatch(std::move(net_query));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
2019-07-11 13:25:20 +02:00
|
|
|
DcOption option_;
|
2018-12-31 20:04:05 +01:00
|
|
|
size_t request_raw_connection_cnt_{0};
|
2018-09-27 03:19:03 +02:00
|
|
|
std::vector<Promise<unique_ptr<mtproto::RawConnection>>> delay_forever_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class SimpleAuthData final : public AuthDataShared {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2018-05-18 13:38:49 +02:00
|
|
|
explicit SimpleAuthData(DcId dc_id) : dc_id_(dc_id) {
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
DcId dc_id() const final {
|
2018-05-18 13:38:49 +02:00
|
|
|
return dc_id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
const std::shared_ptr<PublicRsaKeyShared> &public_rsa_key() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
return public_rsa_key_;
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
mtproto::AuthKey get_auth_key() final {
|
2018-05-18 13:38:49 +02:00
|
|
|
string dc_key = G()->td_db()->get_binlog_pmc()->get(auth_key_key());
|
|
|
|
|
|
|
|
mtproto::AuthKey res;
|
|
|
|
if (!dc_key.empty()) {
|
|
|
|
unserialize(res, dc_key).ensure();
|
|
|
|
}
|
|
|
|
return res;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void set_auth_key(const mtproto::AuthKey &auth_key) final {
|
2018-05-18 13:38:49 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set(auth_key_key(), serialize(auth_key));
|
|
|
|
|
|
|
|
//notify();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2023-05-14 20:58:54 +02:00
|
|
|
void update_server_time_difference(double diff, bool force) final {
|
|
|
|
G()->update_server_time_difference(diff, force);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
double get_server_time_difference() final {
|
2018-05-18 13:38:49 +02:00
|
|
|
return G()->get_server_time_difference();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void add_auth_key_listener(unique_ptr<Listener> listener) final {
|
2023-01-30 16:21:57 +01:00
|
|
|
CHECK(listener != nullptr);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (listener->notify()) {
|
|
|
|
auth_key_listeners_.push_back(std::move(listener));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void set_future_salts(const std::vector<mtproto::ServerSalt> &future_salts) final {
|
2018-05-18 13:38:49 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set(future_salts_key(), serialize(future_salts));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-05-18 13:38:49 +02:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
std::vector<mtproto::ServerSalt> get_future_salts() final {
|
2018-05-18 13:38:49 +02:00
|
|
|
string future_salts = G()->td_db()->get_binlog_pmc()->get(future_salts_key());
|
|
|
|
std::vector<mtproto::ServerSalt> res;
|
|
|
|
if (!future_salts.empty()) {
|
|
|
|
unserialize(res, future_salts).ensure();
|
|
|
|
}
|
|
|
|
return res;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-05-18 13:38:49 +02:00
|
|
|
DcId dc_id_;
|
2019-01-02 00:43:37 +01:00
|
|
|
std::shared_ptr<PublicRsaKeyShared> public_rsa_key_ =
|
|
|
|
std::make_shared<PublicRsaKeyShared>(DcId::empty(), G()->is_test_dc());
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-09-27 03:19:03 +02:00
|
|
|
std::vector<unique_ptr<Listener>> auth_key_listeners_;
|
2018-12-31 20:04:05 +01:00
|
|
|
void notify() {
|
2023-01-30 16:21:57 +01:00
|
|
|
td::remove_if(auth_key_listeners_, [&](auto &listener) {
|
|
|
|
CHECK(listener != nullptr);
|
|
|
|
return !listener->notify();
|
|
|
|
});
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-05-18 13:38:49 +02:00
|
|
|
|
2018-05-18 18:44:46 +02:00
|
|
|
string auth_key_key() const {
|
2018-05-18 13:38:49 +02:00
|
|
|
return PSTRING() << "config_recovery_auth" << dc_id().get_raw_id();
|
|
|
|
}
|
2018-05-18 18:44:46 +02:00
|
|
|
string future_salts_key() const {
|
2018-05-18 13:38:49 +02:00
|
|
|
return PSTRING() << "config_recovery_salt" << dc_id().get_raw_id();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class GetConfigActor final : public NetQueryCallback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2021-10-19 17:11:16 +02:00
|
|
|
GetConfigActor(DcOption option, Promise<tl_object_ptr<telegram_api::config>> promise, ActorShared<> parent)
|
2019-08-09 14:14:07 +02:00
|
|
|
: option_(std::move(option)), promise_(std::move(promise)), parent_(std::move(parent)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final {
|
2019-07-11 13:25:20 +02:00
|
|
|
auto auth_data = std::make_shared<SimpleAuthData>(option_.get_dc_id());
|
2019-12-18 01:47:51 +01:00
|
|
|
int32 raw_dc_id = option_.get_dc_id().get_raw_id();
|
2019-07-11 13:25:20 +02:00
|
|
|
auto session_callback = make_unique<SessionCallback>(actor_shared(this, 1), std::move(option_));
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-12-18 01:47:51 +01:00
|
|
|
int32 int_dc_id = raw_dc_id;
|
2018-05-23 18:49:05 +02:00
|
|
|
if (G()->is_test_dc()) {
|
|
|
|
int_dc_id += 10000;
|
|
|
|
}
|
2019-12-18 01:47:51 +01:00
|
|
|
session_ = create_actor<Session>("ConfigSession", std::move(session_callback), std::move(auth_data), raw_dc_id,
|
2023-01-14 22:25:22 +01:00
|
|
|
int_dc_id, false /*is_primary*/, false /*is_main*/, true /*use_pfs*/,
|
|
|
|
false /*is_cdn*/, false /*need_destroy_auth_key*/, mtproto::AuthKey(),
|
2019-12-18 01:47:51 +01:00
|
|
|
std::vector<mtproto::ServerSalt>());
|
2020-03-15 23:01:14 +01:00
|
|
|
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), DcId::empty());
|
2020-06-10 01:44:54 +02:00
|
|
|
query->total_timeout_limit_ = 60 * 60 * 24;
|
2018-12-31 20:04:05 +01:00
|
|
|
query->set_callback(actor_shared(this));
|
2020-06-10 01:44:54 +02:00
|
|
|
query->dispatch_ttl_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(session_, &Session::send, std::move(query));
|
|
|
|
set_timeout_in(10);
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_result(NetQueryPtr query) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
promise_.set_result(fetch_result<telegram_api::help_getConfig>(std::move(query)));
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup_shared() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (get_link_token() == 1) {
|
2018-05-18 13:38:49 +02:00
|
|
|
if (promise_) {
|
|
|
|
promise_.set_error(Status::Error("Failed"));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
session_.reset();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void timeout_expired() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
promise_.set_error(Status::Error("Timeout expired"));
|
2018-05-18 13:38:49 +02:00
|
|
|
session_.reset();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
DcOption option_;
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorOwn<Session> session_;
|
2021-10-19 17:11:16 +02:00
|
|
|
Promise<tl_object_ptr<telegram_api::config>> promise_;
|
2019-08-09 14:14:07 +02:00
|
|
|
ActorShared<> parent_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
return ActorOwn<>(
|
|
|
|
create_actor<GetConfigActor>("GetConfigActor", std::move(option), std::move(promise), std::move(parent)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class ConfigRecoverer final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit ConfigRecoverer(ActorShared<> parent) : parent_(std::move(parent)) {
|
2020-06-18 01:42:01 +02:00
|
|
|
connecting_since_ = Time::now();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_dc_options_update(DcOptions dc_options) {
|
2021-10-19 17:11:16 +02:00
|
|
|
dc_options_update_ = std::move(dc_options);
|
2018-12-31 20:04:05 +01:00
|
|
|
update_dc_options();
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void on_network(bool has_network, uint32 network_generation) {
|
|
|
|
has_network_ = has_network;
|
|
|
|
if (network_generation_ != network_generation) {
|
|
|
|
if (has_network_) {
|
|
|
|
has_network_since_ = Time::now_cached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
void on_online(bool is_online) {
|
2018-08-04 23:35:50 +02:00
|
|
|
if (is_online_ == is_online) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
is_online_ = is_online;
|
2018-08-04 23:35:50 +02:00
|
|
|
if (is_online) {
|
|
|
|
if (simple_config_.dc_options.empty()) {
|
2019-02-10 01:45:15 +01:00
|
|
|
simple_config_expires_at_ = 0;
|
2018-08-04 23:35:50 +02:00
|
|
|
}
|
|
|
|
if (full_config_ == nullptr) {
|
2019-02-10 01:45:15 +01:00
|
|
|
full_config_expires_at_ = 0;
|
2018-08-04 23:35:50 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
loop();
|
|
|
|
}
|
|
|
|
void on_connecting(bool is_connecting) {
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "On connecting " << is_connecting;
|
2018-12-31 20:04:05 +01:00
|
|
|
if (is_connecting && !is_connecting_) {
|
|
|
|
connecting_since_ = Time::now_cached();
|
|
|
|
}
|
|
|
|
is_connecting_ = is_connecting;
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
2018-05-24 17:09:27 +02:00
|
|
|
static bool check_phone_number_rules(Slice phone_number, Slice rules) {
|
2018-05-24 18:40:00 +02:00
|
|
|
if (rules.empty() || phone_number.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-24 17:09:27 +02:00
|
|
|
bool found = false;
|
|
|
|
for (auto prefix : full_split(rules, ',')) {
|
|
|
|
if (prefix.empty()) {
|
|
|
|
found = true;
|
|
|
|
} else if (prefix[0] == '+' && begins_with(phone_number, prefix.substr(1))) {
|
|
|
|
found = true;
|
|
|
|
} else if (prefix[0] == '-' && begins_with(phone_number, prefix.substr(1))) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Invalid prefix rule " << prefix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
void on_simple_config(Result<SimpleConfigResult> r_simple_config_result, bool dummy) {
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_query_.reset();
|
|
|
|
dc_options_i_ = 0;
|
2019-07-11 13:25:20 +02:00
|
|
|
|
|
|
|
SimpleConfigResult cfg;
|
|
|
|
if (r_simple_config_result.is_error()) {
|
|
|
|
cfg.r_http_date = r_simple_config_result.error().clone();
|
|
|
|
cfg.r_config = r_simple_config_result.move_as_error();
|
|
|
|
} else {
|
|
|
|
cfg = r_simple_config_result.move_as_ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg.r_http_date.is_ok() && (date_option_i_ == 0 || cfg.r_config.is_error())) {
|
|
|
|
G()->update_dns_time_difference(cfg.r_http_date.ok() - Time::now());
|
|
|
|
} else if (cfg.r_config.is_ok()) {
|
|
|
|
G()->update_dns_time_difference(cfg.r_config.ok()->date_ - Time::now());
|
|
|
|
}
|
|
|
|
date_option_i_ = (date_option_i_ + 1) % 2;
|
|
|
|
|
|
|
|
do_on_simple_config(std::move(cfg.r_config));
|
|
|
|
update_dc_options();
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_on_simple_config(Result<SimpleConfig> r_simple_config) {
|
2018-05-24 17:09:27 +02:00
|
|
|
if (r_simple_config.is_ok()) {
|
|
|
|
auto config = r_simple_config.move_as_ok();
|
2018-11-17 22:24:19 +01:00
|
|
|
VLOG(config_recoverer) << "Receive raw " << to_string(config);
|
2018-05-24 17:09:27 +02:00
|
|
|
if (config->expires_ >= G()->unix_time()) {
|
2022-08-17 15:11:13 +02:00
|
|
|
string phone_number = G()->get_option_string("my_phone_number");
|
2018-05-24 17:09:27 +02:00
|
|
|
simple_config_.dc_options.clear();
|
|
|
|
|
|
|
|
for (auto &rule : config->rules_) {
|
|
|
|
if (check_phone_number_rules(phone_number, rule->phone_prefix_rules_) && DcId::is_valid(rule->dc_id_)) {
|
|
|
|
DcId dc_id = DcId::internal(rule->dc_id_);
|
|
|
|
for (auto &ip_port : rule->ips_) {
|
|
|
|
DcOption option(dc_id, *ip_port);
|
|
|
|
if (option.is_valid()) {
|
|
|
|
simple_config_.dc_options.push_back(std::move(option));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 12:22:31 +01:00
|
|
|
VLOG(config_recoverer) << "Receive SimpleConfig " << simple_config_;
|
2019-01-23 04:13:51 +01:00
|
|
|
} else {
|
|
|
|
VLOG(config_recoverer) << "Config has expired at " << config->expires_;
|
2018-05-24 17:09:27 +02:00
|
|
|
}
|
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
simple_config_expires_at_ = get_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_at_ = Time::now_cached();
|
|
|
|
for (size_t i = 1; i < simple_config_.dc_options.size(); i++) {
|
|
|
|
std::swap(simple_config_.dc_options[i], simple_config_.dc_options[Random::fast(0, static_cast<int>(i))]);
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-24 17:09:27 +02:00
|
|
|
VLOG(config_recoverer) << "Get SimpleConfig error " << r_simple_config.error();
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_ = DcOptions();
|
2019-02-10 01:45:15 +01:00
|
|
|
simple_config_expires_at_ = get_failed_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
void on_full_config(Result<tl_object_ptr<telegram_api::config>> r_full_config, bool dummy) {
|
2018-12-31 20:04:05 +01:00
|
|
|
full_config_query_.reset();
|
|
|
|
if (r_full_config.is_ok()) {
|
|
|
|
full_config_ = r_full_config.move_as_ok();
|
2021-10-19 17:11:16 +02:00
|
|
|
VLOG(config_recoverer) << "Receive " << to_string(full_config_);
|
2019-02-10 01:45:15 +01:00
|
|
|
full_config_expires_at_ = get_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(full_config_->dc_options_));
|
|
|
|
} else {
|
2021-10-19 17:11:16 +02:00
|
|
|
VLOG(config_recoverer) << "Failed to get config: " << r_full_config.error();
|
|
|
|
full_config_ = nullptr;
|
2019-02-10 01:45:15 +01:00
|
|
|
full_config_expires_at_ = get_failed_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
static bool expect_blocking() {
|
2022-08-17 15:11:13 +02:00
|
|
|
return G()->get_option_boolean("expect_blocking", true);
|
2018-05-03 12:18:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double get_config_expire_time() const {
|
2018-08-04 23:35:50 +02:00
|
|
|
auto offline_delay = is_online_ ? 0 : 5 * 60;
|
|
|
|
auto expire_time = expect_blocking() ? Random::fast(2 * 60, 3 * 60) : Random::fast(20 * 60, 30 * 60);
|
|
|
|
return Time::now() + offline_delay + expire_time;
|
2018-05-03 12:18:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double get_failed_config_expire_time() const {
|
2018-08-04 23:35:50 +02:00
|
|
|
auto offline_delay = is_online_ ? 0 : 5 * 60;
|
|
|
|
auto expire_time = expect_blocking() ? Random::fast(5, 7) : Random::fast(15, 30);
|
|
|
|
return Time::now() + offline_delay + expire_time;
|
2018-05-03 12:18:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_connecting_{false};
|
|
|
|
double connecting_since_{0};
|
|
|
|
|
|
|
|
bool is_online_{false};
|
|
|
|
|
|
|
|
bool has_network_{false};
|
|
|
|
double has_network_since_{0};
|
|
|
|
uint32 network_generation_{0};
|
|
|
|
|
|
|
|
DcOptions simple_config_;
|
2019-02-10 01:45:15 +01:00
|
|
|
double simple_config_expires_at_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
double simple_config_at_{0};
|
|
|
|
ActorOwn<> simple_config_query_;
|
|
|
|
|
|
|
|
DcOptions dc_options_update_;
|
|
|
|
|
|
|
|
DcOptions dc_options_; // dc_options_update_ + simple_config_
|
|
|
|
double dc_options_at_{0};
|
2021-11-11 15:39:09 +01:00
|
|
|
size_t dc_options_i_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
size_t date_option_i_{0};
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
tl_object_ptr<telegram_api::config> full_config_;
|
2019-02-10 01:45:15 +01:00
|
|
|
double full_config_expires_at_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorOwn<> full_config_query_;
|
|
|
|
|
|
|
|
uint32 ref_cnt_{1};
|
|
|
|
bool close_flag_{false};
|
2020-06-01 22:52:25 +02:00
|
|
|
uint32 simple_config_turn_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup_shared() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
ref_cnt_--;
|
|
|
|
try_stop();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
ref_cnt_--;
|
|
|
|
close_flag_ = true;
|
|
|
|
full_config_query_.reset();
|
|
|
|
simple_config_query_.reset();
|
|
|
|
try_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void try_stop() {
|
|
|
|
if (ref_cnt_ == 0) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double max_connecting_delay() const {
|
2018-05-03 12:18:07 +02:00
|
|
|
return expect_blocking() ? 5 : 20;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-10-19 17:11:16 +02:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void loop() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (close_flag_) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-10 16:03:38 +02:00
|
|
|
if (Session::is_high_loaded()) {
|
|
|
|
VLOG(config_recoverer) << "Skip config recoverer under high load";
|
|
|
|
set_timeout_in(Random::fast(200, 300));
|
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-02-07 21:48:40 +01:00
|
|
|
if (is_connecting_) {
|
2022-12-10 23:32:46 +01:00
|
|
|
VLOG(config_recoverer) << "Failed to connect for " << Time::now() - connecting_since_ << " seconds";
|
2018-02-07 21:48:40 +01:00
|
|
|
} else {
|
2022-12-10 23:32:46 +01:00
|
|
|
VLOG(config_recoverer) << "Successfully connected in " << Time::now() - connecting_since_ << " seconds";
|
2018-02-07 21:48:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
Timestamp wakeup_timestamp;
|
|
|
|
auto check_timeout = [&](Timestamp timestamp) {
|
|
|
|
if (timestamp.at() < Time::now_cached()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
wakeup_timestamp.relax(timestamp);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool has_connecting_problem =
|
|
|
|
is_connecting_ && check_timeout(Timestamp::at(connecting_since_ + max_connecting_delay()));
|
2019-02-10 01:45:15 +01:00
|
|
|
bool is_valid_simple_config = !check_timeout(Timestamp::at(simple_config_expires_at_));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!is_valid_simple_config && !simple_config_.dc_options.empty()) {
|
|
|
|
simple_config_ = DcOptions();
|
|
|
|
update_dc_options();
|
|
|
|
}
|
|
|
|
bool need_simple_config = has_connecting_problem && !is_valid_simple_config && simple_config_query_.empty();
|
|
|
|
bool has_dc_options = !dc_options_.dc_options.empty();
|
2019-02-10 01:45:15 +01:00
|
|
|
bool is_valid_full_config = !check_timeout(Timestamp::at(full_config_expires_at_));
|
2018-12-31 20:04:05 +01:00
|
|
|
bool need_full_config = has_connecting_problem && has_dc_options && !is_valid_full_config &&
|
2018-05-03 12:18:07 +02:00
|
|
|
full_config_query_.empty() &&
|
|
|
|
check_timeout(Timestamp::at(dc_options_at_ + (expect_blocking() ? 5 : 10)));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (need_simple_config) {
|
|
|
|
ref_cnt_++;
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Ask simple config with turn " << simple_config_turn_;
|
2022-03-05 12:35:19 +01:00
|
|
|
auto promise = PromiseCreator::lambda([self = actor_shared(this)](Result<SimpleConfigResult> r_simple_config) {
|
|
|
|
send_closure(self, &ConfigRecoverer::on_simple_config, std::move(r_simple_config), false);
|
|
|
|
});
|
2020-02-26 16:15:19 +01:00
|
|
|
auto get_simple_config = [&] {
|
2020-06-01 22:52:25 +02:00
|
|
|
switch (simple_config_turn_ % 10) {
|
|
|
|
case 6:
|
2018-05-24 17:09:27 +02:00
|
|
|
return get_simple_config_azure;
|
2020-06-01 22:52:25 +02:00
|
|
|
case 2:
|
2019-11-19 15:58:24 +01:00
|
|
|
return get_simple_config_firebase_remote_config;
|
2019-11-19 17:01:12 +01:00
|
|
|
case 4:
|
2019-11-19 17:26:39 +01:00
|
|
|
return get_simple_config_firebase_firestore;
|
2023-01-10 18:03:05 +01:00
|
|
|
case 9:
|
|
|
|
return get_simple_config_firebase_realtime;
|
2018-05-24 17:09:27 +02:00
|
|
|
case 0:
|
2020-06-01 22:52:25 +02:00
|
|
|
case 3:
|
|
|
|
case 8:
|
2018-03-12 19:04:03 +01:00
|
|
|
return get_simple_config_google_dns;
|
2019-10-03 21:28:01 +02:00
|
|
|
case 1:
|
2020-06-01 22:52:25 +02:00
|
|
|
case 5:
|
|
|
|
case 7:
|
2019-10-03 21:28:01 +02:00
|
|
|
default:
|
|
|
|
return get_simple_config_mozilla_dns;
|
2018-03-12 19:04:03 +01:00
|
|
|
}
|
|
|
|
}();
|
2022-08-18 20:45:29 +02:00
|
|
|
simple_config_query_ = get_simple_config(std::move(promise), G()->get_option_boolean("prefer_ipv6"),
|
|
|
|
G()->get_option_string("dc_txt_domain_name"), G()->is_test_dc(),
|
|
|
|
G()->get_gc_scheduler_id());
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_turn_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_full_config) {
|
|
|
|
ref_cnt_++;
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Ask full config with dc_options_i_ = " << dc_options_i_;
|
2021-10-19 17:11:16 +02:00
|
|
|
full_config_query_ = get_full_config(
|
|
|
|
dc_options_.dc_options[dc_options_i_],
|
|
|
|
PromiseCreator::lambda(
|
|
|
|
[actor_id = actor_id(this)](Result<tl_object_ptr<telegram_api::config>> r_full_config) {
|
|
|
|
send_closure(actor_id, &ConfigRecoverer::on_full_config, std::move(r_full_config), false);
|
|
|
|
}),
|
|
|
|
actor_shared(this));
|
2018-12-31 20:04:05 +01:00
|
|
|
dc_options_i_ = (dc_options_i_ + 1) % dc_options_.dc_options.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wakeup_timestamp) {
|
|
|
|
VLOG(config_recoverer) << "Wakeup in " << format::as_time(wakeup_timestamp.in());
|
|
|
|
set_timeout_at(wakeup_timestamp.at());
|
|
|
|
} else {
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Wakeup never";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final {
|
2021-07-04 04:58:54 +02:00
|
|
|
class StateCallback final : public StateManager::Callback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit StateCallback(ActorId<ConfigRecoverer> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
2021-09-16 17:23:10 +02:00
|
|
|
bool on_state(ConnectionState state) final {
|
|
|
|
send_closure(parent_, &ConfigRecoverer::on_connecting, state == ConnectionState::Connecting);
|
2018-12-31 20:04:05 +01:00
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
bool on_network(NetType network_type, uint32 network_generation) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(parent_, &ConfigRecoverer::on_network, network_type != NetType::None, network_generation);
|
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
bool on_online(bool online_flag) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(parent_, &ConfigRecoverer::on_online, online_flag);
|
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ActorId<ConfigRecoverer> parent_;
|
|
|
|
};
|
|
|
|
send_closure(G()->state_manager(), &StateManager::add_callback, make_unique<StateCallback>(actor_id(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_dc_options() {
|
2020-06-24 13:33:20 +02:00
|
|
|
auto new_dc_options = simple_config_.dc_options;
|
|
|
|
new_dc_options.insert(new_dc_options.begin(), dc_options_update_.dc_options.begin(),
|
|
|
|
dc_options_update_.dc_options.end());
|
|
|
|
if (new_dc_options != dc_options_.dc_options) {
|
|
|
|
dc_options_.dc_options = std::move(new_dc_options);
|
2018-12-31 20:04:05 +01:00
|
|
|
dc_options_i_ = 0;
|
|
|
|
dc_options_at_ = Time::now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-15 21:33:30 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void ConfigManager::AppConfig::store(StorerT &storer) const {
|
|
|
|
td::store(version_, storer);
|
|
|
|
td::store(hash_, storer);
|
|
|
|
config_->store(storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void ConfigManager::AppConfig::parse(ParserT &parser) {
|
|
|
|
td::parse(version_, parser);
|
|
|
|
if (version_ != CURRENT_VERSION) {
|
|
|
|
return parser.set_error("Invalid config version");
|
|
|
|
}
|
|
|
|
td::parse(hash_, parser);
|
|
|
|
auto buffer = parser.template fetch_string_raw<BufferSlice>(parser.get_left_len());
|
|
|
|
TlBufferParser buffer_parser{&buffer};
|
2023-02-21 11:34:36 +01:00
|
|
|
config_ = telegram_api::jsonObject::fetch(buffer_parser);
|
|
|
|
buffer_parser.fetch_end();
|
|
|
|
if (buffer_parser.get_error() != nullptr) {
|
|
|
|
return parser.set_error(buffer_parser.get_error());
|
|
|
|
}
|
2023-02-15 21:33:30 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
ConfigManager::ConfigManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
2020-08-23 19:34:05 +02:00
|
|
|
lazy_request_flood_control_.add_limit(20, 1);
|
2023-02-15 21:33:30 +01:00
|
|
|
|
2023-02-21 11:34:36 +01:00
|
|
|
if (log_event_parse(app_config_, G()->td_db()->get_binlog_pmc()->get("app_config")).is_error()) {
|
|
|
|
app_config_ = AppConfig();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::start_up() {
|
2020-08-11 15:31:50 +02:00
|
|
|
config_recoverer_ = create_actor<ConfigRecoverer>("Recoverer", create_reference());
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, load_dc_options_update());
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
auto expire_time = load_config_expire_time();
|
2020-07-26 14:41:32 +02:00
|
|
|
if (expire_time.is_in_past() || true) {
|
2022-06-06 19:36:15 +02:00
|
|
|
request_config(false);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = expire_time;
|
|
|
|
set_timeout_in(expire_time_.in());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 15:31:50 +02:00
|
|
|
ActorShared<> ConfigManager::create_reference() {
|
|
|
|
ref_cnt_++;
|
|
|
|
return actor_shared(this, REFCNT_TOKEN);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::hangup_shared() {
|
2023-02-26 12:22:31 +01:00
|
|
|
LOG_CHECK(get_link_token() == REFCNT_TOKEN)
|
|
|
|
<< "Expected link token " << REFCNT_TOKEN << ", but receive " << get_link_token();
|
2018-12-31 20:04:05 +01:00
|
|
|
ref_cnt_--;
|
|
|
|
try_stop();
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::hangup() {
|
|
|
|
ref_cnt_--;
|
|
|
|
config_recoverer_.reset();
|
|
|
|
try_stop();
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::loop() {
|
2019-02-10 01:45:15 +01:00
|
|
|
if (expire_time_ && expire_time_.is_in_past()) {
|
2022-06-06 19:36:15 +02:00
|
|
|
request_config(reopen_sessions_after_get_config_);
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = {};
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::try_stop() {
|
|
|
|
if (ref_cnt_ == 0) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2022-06-06 19:36:15 +02:00
|
|
|
void ConfigManager::request_config(bool reopen_sessions) {
|
2019-12-19 21:00:28 +01:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:36:15 +02:00
|
|
|
if (config_sent_cnt_ != 0 && !reopen_sessions) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-07-16 21:36:59 +02:00
|
|
|
|
2022-11-21 19:07:56 +01:00
|
|
|
lazy_request_flood_control_.add_event(Time::now());
|
2022-06-06 19:36:15 +02:00
|
|
|
request_config_from_dc_impl(DcId::main(), reopen_sessions);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 20:37:13 +02:00
|
|
|
void ConfigManager::lazy_request_config() {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config_sent_cnt_ != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-23 19:34:05 +02:00
|
|
|
expire_time_.relax(Timestamp::at(lazy_request_flood_control_.get_wakeup_at()));
|
2020-07-16 20:37:13 +02:00
|
|
|
set_timeout_at(expire_time_.at());
|
|
|
|
}
|
|
|
|
|
2023-02-07 12:01:45 +01:00
|
|
|
void ConfigManager::reget_config(Promise<Unit> &&promise) {
|
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
|
|
|
|
|
|
|
reget_config_queries_.push_back(std::move(promise));
|
|
|
|
if (reget_config_queries_.size() != 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
request_config_from_dc_impl(DcId::main(), false);
|
|
|
|
}
|
|
|
|
|
2021-10-06 00:17:10 +02:00
|
|
|
void ConfigManager::try_request_app_config() {
|
|
|
|
if (get_app_config_queries_.size() + reget_app_config_queries_.size() != 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-15 21:33:30 +01:00
|
|
|
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getAppConfig(app_config_.hash_));
|
2021-10-06 00:17:10 +02:00
|
|
|
query->total_timeout_limit_ = 60 * 60 * 24;
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, 1));
|
|
|
|
}
|
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
void ConfigManager::get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise) {
|
2021-10-07 15:36:21 +02:00
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
2019-12-19 21:00:28 +01:00
|
|
|
|
2019-12-23 14:14:43 +01:00
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
|
|
|
if (auth_manager != nullptr && auth_manager->is_bot()) {
|
|
|
|
return promise.set_value(nullptr);
|
|
|
|
}
|
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
get_app_config_queries_.push_back(std::move(promise));
|
2021-10-06 00:17:10 +02:00
|
|
|
try_request_app_config();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::reget_app_config(Promise<Unit> &&promise) {
|
2023-02-17 14:14:31 +01:00
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
2021-10-06 00:17:10 +02:00
|
|
|
|
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
|
|
|
if (auth_manager != nullptr && auth_manager->is_bot()) {
|
|
|
|
return promise.set_value(Unit());
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
2021-10-06 00:17:10 +02:00
|
|
|
|
|
|
|
reget_app_config_queries_.push_back(std::move(promise));
|
|
|
|
try_request_app_config();
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 21:00:28 +01:00
|
|
|
void ConfigManager::get_content_settings(Promise<Unit> &&promise) {
|
2021-10-07 15:36:21 +02:00
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
2019-12-19 21:00:28 +01:00
|
|
|
|
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
2019-12-20 14:16:30 +01:00
|
|
|
if (auth_manager == nullptr || !auth_manager->is_authorized() || auth_manager->is_bot()) {
|
2019-12-19 21:00:28 +01:00
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
get_content_settings_queries_.push_back(std::move(promise));
|
|
|
|
if (get_content_settings_queries_.size() == 1) {
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
2020-03-15 22:17:11 +01:00
|
|
|
G()->net_query_creator().create(telegram_api::account_getContentSettings()), actor_shared(this, 2));
|
2019-12-19 21:00:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 00:58:41 +01:00
|
|
|
void ConfigManager::set_content_settings(bool ignore_sensitive_content_restrictions, Promise<Unit> &&promise) {
|
2021-10-07 15:36:21 +02:00
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
2019-12-20 00:58:41 +01:00
|
|
|
|
2019-12-20 02:06:38 +01:00
|
|
|
last_set_content_settings_ = ignore_sensitive_content_restrictions;
|
2019-12-20 00:58:41 +01:00
|
|
|
auto &queries = set_content_settings_queries_[ignore_sensitive_content_restrictions];
|
|
|
|
queries.push_back(std::move(promise));
|
|
|
|
if (!is_set_content_settings_request_sent_) {
|
|
|
|
is_set_content_settings_request_sent_ = true;
|
|
|
|
int32 flags = 0;
|
|
|
|
if (ignore_sensitive_content_restrictions) {
|
|
|
|
flags |= telegram_api::account_setContentSettings::SENSITIVE_ENABLED_MASK;
|
|
|
|
}
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
2020-03-15 22:17:11 +01:00
|
|
|
G()->net_query_creator().create(telegram_api::account_setContentSettings(flags, false /*ignored*/)),
|
2019-12-20 00:58:41 +01:00
|
|
|
actor_shared(this, 3 + static_cast<uint64>(ignore_sensitive_content_restrictions)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void ConfigManager::get_global_privacy_settings(Promise<Unit> &&promise) {
|
2021-10-07 15:36:21 +02:00
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
2020-07-10 19:28:30 +02:00
|
|
|
|
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
|
|
|
if (auth_manager == nullptr || !auth_manager->is_authorized() || auth_manager->is_bot()) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
get_global_privacy_settings_queries_.push_back(std::move(promise));
|
|
|
|
if (get_global_privacy_settings_queries_.size() == 1) {
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
|
|
|
G()->net_query_creator().create(telegram_api::account_getGlobalPrivacySettings()), actor_shared(this, 5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::set_archive_and_mute(bool archive_and_mute, Promise<Unit> &&promise) {
|
2021-10-07 15:36:21 +02:00
|
|
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
|
|
|
|
2020-07-11 22:50:21 +02:00
|
|
|
if (archive_and_mute) {
|
2021-02-22 16:25:49 +01:00
|
|
|
remove_suggested_action(suggested_actions_, SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats});
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
2020-07-10 19:28:30 +02:00
|
|
|
|
|
|
|
last_set_archive_and_mute_ = archive_and_mute;
|
|
|
|
auto &queries = set_archive_and_mute_queries_[archive_and_mute];
|
|
|
|
queries.push_back(std::move(promise));
|
|
|
|
if (!is_set_archive_and_mute_request_sent_) {
|
|
|
|
is_set_archive_and_mute_request_sent_ = true;
|
2023-05-01 20:07:01 +02:00
|
|
|
int32 flags = 0;
|
|
|
|
if (archive_and_mute) {
|
|
|
|
flags |= telegram_api::globalPrivacySettings::ARCHIVE_AND_MUTE_NEW_NONCONTACT_PEERS_MASK;
|
|
|
|
}
|
|
|
|
auto settings = make_tl_object<telegram_api::globalPrivacySettings>(flags, false /*ignored*/, false /*ignored*/,
|
|
|
|
false /*ignored*/);
|
2020-07-10 19:28:30 +02:00
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
|
|
|
G()->net_query_creator().create(telegram_api::account_setGlobalPrivacySettings(std::move(settings))),
|
|
|
|
actor_shared(this, 6 + static_cast<uint64>(archive_and_mute)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::on_dc_options_update(DcOptions dc_options) {
|
|
|
|
save_dc_options_update(dc_options);
|
2021-10-17 12:07:20 +02:00
|
|
|
if (!dc_options.dc_options.empty()) {
|
|
|
|
expire_time_ = Timestamp::now();
|
|
|
|
save_config_expire(expire_time_);
|
|
|
|
set_timeout_in(expire_time_.in());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-10-17 12:07:20 +02:00
|
|
|
send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, std::move(dc_options));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 19:36:15 +02:00
|
|
|
void ConfigManager::request_config_from_dc_impl(DcId dc_id, bool reopen_sessions) {
|
2018-12-31 20:04:05 +01:00
|
|
|
config_sent_cnt_++;
|
2022-06-06 19:36:15 +02:00
|
|
|
reopen_sessions_after_get_config_ |= reopen_sessions;
|
2020-03-15 23:01:14 +01:00
|
|
|
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), dc_id);
|
2020-06-10 01:44:54 +02:00
|
|
|
query->total_timeout_limit_ = 60 * 60 * 24;
|
2022-06-06 19:36:15 +02:00
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(std::move(query),
|
|
|
|
actor_shared(this, 8 + static_cast<uint64>(reopen_sessions)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void ConfigManager::do_set_ignore_sensitive_content_restrictions(bool ignore_sensitive_content_restrictions) {
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_boolean("ignore_sensitive_content_restrictions", ignore_sensitive_content_restrictions);
|
|
|
|
bool have_ignored_restriction_reasons = G()->have_option("ignored_restriction_reasons");
|
2019-12-20 02:19:40 +01:00
|
|
|
if (have_ignored_restriction_reasons != ignore_sensitive_content_restrictions) {
|
2021-10-06 00:17:10 +02:00
|
|
|
reget_app_config(Auto());
|
2019-12-20 02:19:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void ConfigManager::do_set_archive_and_mute(bool archive_and_mute) {
|
2020-07-11 22:50:21 +02:00
|
|
|
if (archive_and_mute) {
|
2021-02-22 16:25:49 +01:00
|
|
|
remove_suggested_action(suggested_actions_, SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats});
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_boolean("archive_and_mute_new_chats_from_unknown_users", archive_and_mute);
|
2020-07-10 19:28:30 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 01:13:46 +02:00
|
|
|
void ConfigManager::hide_suggested_action(SuggestedAction suggested_action) {
|
|
|
|
remove_suggested_action(suggested_actions_, suggested_action);
|
|
|
|
}
|
|
|
|
|
2020-07-12 14:04:49 +02:00
|
|
|
void ConfigManager::dismiss_suggested_action(SuggestedAction suggested_action, Promise<Unit> &&promise) {
|
2021-02-20 23:06:45 +01:00
|
|
|
auto action_str = suggested_action.get_suggested_action_str();
|
2020-07-12 14:04:49 +02:00
|
|
|
if (action_str.empty()) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!td::contains(suggested_actions_, suggested_action)) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
dismiss_suggested_action_request_count_++;
|
2021-02-20 23:06:45 +01:00
|
|
|
auto type = static_cast<int32>(suggested_action.type_);
|
|
|
|
auto &queries = dismiss_suggested_action_queries_[type];
|
2020-07-12 14:04:49 +02:00
|
|
|
queries.push_back(std::move(promise));
|
|
|
|
if (queries.size() == 1) {
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
2021-02-02 00:00:28 +01:00
|
|
|
G()->net_query_creator().create(
|
|
|
|
telegram_api::help_dismissSuggestion(make_tl_object<telegram_api::inputPeerEmpty>(), action_str)),
|
2021-02-20 23:06:45 +01:00
|
|
|
actor_shared(this, 100 + type));
|
2020-07-12 14:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::on_result(NetQueryPtr res) {
|
2019-12-19 02:23:14 +01:00
|
|
|
auto token = get_link_token();
|
2020-07-12 14:04:49 +02:00
|
|
|
if (token >= 100 && token <= 200) {
|
2021-02-20 23:06:45 +01:00
|
|
|
auto type = static_cast<int32>(token - 100);
|
|
|
|
SuggestedAction suggested_action{static_cast<SuggestedAction::Type>(type)};
|
|
|
|
auto promises = std::move(dismiss_suggested_action_queries_[type]);
|
|
|
|
dismiss_suggested_action_queries_.erase(type);
|
2020-07-12 14:04:49 +02:00
|
|
|
CHECK(!promises.empty());
|
|
|
|
CHECK(dismiss_suggested_action_request_count_ >= promises.size());
|
|
|
|
dismiss_suggested_action_request_count_ -= promises.size();
|
|
|
|
|
|
|
|
auto result_ptr = fetch_result<telegram_api::help_dismissSuggestion>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
2022-04-13 16:40:12 +02:00
|
|
|
fail_promises(promises, result_ptr.move_as_error());
|
2020-07-12 14:04:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-02-22 16:25:49 +01:00
|
|
|
remove_suggested_action(suggested_actions_, suggested_action);
|
2021-10-06 00:17:10 +02:00
|
|
|
reget_app_config(Auto());
|
2020-07-12 14:04:49 +02:00
|
|
|
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(promises);
|
2020-07-12 14:04:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-07-10 19:28:30 +02:00
|
|
|
if (token == 6 || token == 7) {
|
|
|
|
is_set_archive_and_mute_request_sent_ = false;
|
|
|
|
bool archive_and_mute = (token == 7);
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_setGlobalPrivacySettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
2022-04-13 16:40:12 +02:00
|
|
|
fail_promises(set_archive_and_mute_queries_[archive_and_mute], result_ptr.move_as_error());
|
2020-07-10 19:28:30 +02:00
|
|
|
} else {
|
|
|
|
if (last_set_archive_and_mute_ == archive_and_mute) {
|
|
|
|
do_set_archive_and_mute(archive_and_mute);
|
|
|
|
}
|
|
|
|
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(set_archive_and_mute_queries_[archive_and_mute]);
|
2020-07-10 19:28:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!set_archive_and_mute_queries_[!archive_and_mute].empty()) {
|
|
|
|
if (archive_and_mute == last_set_archive_and_mute_) {
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(set_archive_and_mute_queries_[!archive_and_mute]);
|
2020-07-10 19:28:30 +02:00
|
|
|
} else {
|
|
|
|
set_archive_and_mute(!archive_and_mute, Auto());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (token == 5) {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_getGlobalPrivacySettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
2022-04-13 16:40:12 +02:00
|
|
|
fail_promises(get_global_privacy_settings_queries_, result_ptr.move_as_error());
|
2020-07-10 19:28:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = result_ptr.move_as_ok();
|
2023-05-01 20:07:01 +02:00
|
|
|
do_set_archive_and_mute(result->archive_and_mute_new_noncontact_peers_);
|
2020-07-10 19:28:30 +02:00
|
|
|
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(get_global_privacy_settings_queries_);
|
2020-07-10 19:28:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-12-20 00:58:41 +01:00
|
|
|
if (token == 3 || token == 4) {
|
|
|
|
is_set_content_settings_request_sent_ = false;
|
|
|
|
bool ignore_sensitive_content_restrictions = (token == 4);
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_setContentSettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
2022-04-13 16:40:12 +02:00
|
|
|
fail_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions], result_ptr.move_as_error());
|
2019-12-20 00:58:41 +01:00
|
|
|
} else {
|
2022-08-17 15:11:13 +02:00
|
|
|
if (G()->get_option_boolean("can_ignore_sensitive_content_restrictions") &&
|
2019-12-20 02:06:38 +01:00
|
|
|
last_set_content_settings_ == ignore_sensitive_content_restrictions) {
|
2020-07-10 19:28:30 +02:00
|
|
|
do_set_ignore_sensitive_content_restrictions(ignore_sensitive_content_restrictions);
|
2019-12-20 00:58:41 +01:00
|
|
|
}
|
|
|
|
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions]);
|
2019-12-20 00:58:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!set_content_settings_queries_[!ignore_sensitive_content_restrictions].empty()) {
|
2019-12-20 02:06:38 +01:00
|
|
|
if (ignore_sensitive_content_restrictions == last_set_content_settings_) {
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(set_content_settings_queries_[!ignore_sensitive_content_restrictions]);
|
2019-12-20 02:06:38 +01:00
|
|
|
} else {
|
|
|
|
set_content_settings(!ignore_sensitive_content_restrictions, Auto());
|
|
|
|
}
|
2019-12-20 00:58:41 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-12-19 21:00:28 +01:00
|
|
|
if (token == 2) {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_getContentSettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
2022-04-13 16:40:12 +02:00
|
|
|
fail_promises(get_content_settings_queries_, result_ptr.move_as_error());
|
2019-12-19 21:00:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = result_ptr.move_as_ok();
|
2020-07-10 19:28:30 +02:00
|
|
|
do_set_ignore_sensitive_content_restrictions(result->sensitive_enabled_);
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_boolean("can_ignore_sensitive_content_restrictions", result->sensitive_can_change_);
|
2019-12-19 21:00:28 +01:00
|
|
|
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(get_content_settings_queries_);
|
2019-12-19 21:00:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
if (token == 1) {
|
|
|
|
auto promises = std::move(get_app_config_queries_);
|
|
|
|
get_app_config_queries_.clear();
|
2021-10-06 00:17:10 +02:00
|
|
|
auto unit_promises = std::move(reget_app_config_queries_);
|
|
|
|
reget_app_config_queries_.clear();
|
|
|
|
CHECK(!promises.empty() || !unit_promises.empty());
|
2019-12-19 02:23:14 +01:00
|
|
|
auto result_ptr = fetch_result<telegram_api::help_getAppConfig>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
2022-04-13 16:40:12 +02:00
|
|
|
fail_promises(promises, result_ptr.error().clone());
|
|
|
|
fail_promises(unit_promises, result_ptr.move_as_error());
|
2019-12-19 21:00:28 +01:00
|
|
|
return;
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
|
|
|
|
2023-02-07 12:01:45 +01:00
|
|
|
auto app_config_ptr = result_ptr.move_as_ok();
|
|
|
|
if (app_config_ptr->get_id() == telegram_api::help_appConfigNotModified::ID) {
|
2023-02-15 21:33:30 +01:00
|
|
|
if (app_config_.version_ == 0) {
|
|
|
|
LOG(ERROR) << "Receive appConfigNotModified";
|
|
|
|
fail_promises(promises, Status::Error(500, "Receive unexpected response"));
|
|
|
|
fail_promises(unit_promises, Status::Error(500, "Receive unexpected response"));
|
|
|
|
return;
|
|
|
|
}
|
2023-02-21 11:34:36 +01:00
|
|
|
CHECK(app_config_.config_ != nullptr);
|
2023-02-15 21:33:30 +01:00
|
|
|
} else {
|
|
|
|
CHECK(app_config_ptr->get_id() == telegram_api::help_appConfig::ID);
|
|
|
|
auto app_config = telegram_api::move_object_as<telegram_api::help_appConfig>(app_config_ptr);
|
|
|
|
process_app_config(app_config->config_);
|
|
|
|
app_config_.version_ = AppConfig::CURRENT_VERSION;
|
|
|
|
app_config_.hash_ = app_config->hash_;
|
|
|
|
app_config_.config_ = std::move(app_config->config_);
|
2023-02-21 11:34:36 +01:00
|
|
|
CHECK(app_config_.config_ != nullptr);
|
2023-02-15 21:33:30 +01:00
|
|
|
G()->td_db()->get_binlog_pmc()->set("app_config", log_event_store(app_config_).as_slice().str());
|
2023-02-07 12:01:45 +01:00
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
for (auto &promise : promises) {
|
2023-02-15 21:33:30 +01:00
|
|
|
promise.set_value(convert_json_value_object(app_config_.config_));
|
2021-10-06 00:17:10 +02:00
|
|
|
}
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(unit_promises);
|
2019-12-19 02:23:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:36:15 +02:00
|
|
|
CHECK(token == 8 || token == 9);
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(config_sent_cnt_ > 0);
|
|
|
|
config_sent_cnt_--;
|
|
|
|
auto r_config = fetch_result<telegram_api::help_getConfig>(std::move(res));
|
|
|
|
if (r_config.is_error()) {
|
2018-04-19 19:21:26 +02:00
|
|
|
if (!G()->close_flag()) {
|
2020-04-21 02:29:20 +02:00
|
|
|
LOG(WARNING) << "Failed to get config: " << r_config.error();
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = Timestamp::in(60.0); // try again in a minute
|
|
|
|
set_timeout_in(expire_time_.in());
|
2018-04-19 19:21:26 +02:00
|
|
|
}
|
2023-02-07 12:01:45 +01:00
|
|
|
fail_promises(reget_config_queries_, r_config.move_as_error());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
on_dc_options_update(DcOptions());
|
|
|
|
process_config(r_config.move_as_ok());
|
2022-06-06 19:36:15 +02:00
|
|
|
if (token == 9) {
|
|
|
|
G()->net_query_dispatcher().update_mtproto_header();
|
2023-05-09 00:08:45 +02:00
|
|
|
reopen_sessions_after_get_config_ = false;
|
2022-06-06 19:36:15 +02:00
|
|
|
}
|
2023-02-07 12:01:45 +01:00
|
|
|
set_promises(reget_config_queries_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
void ConfigManager::save_dc_options_update(const DcOptions &dc_options) {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (dc_options.dc_options.empty()) {
|
|
|
|
G()->td_db()->get_binlog_pmc()->erase("dc_options_update");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
G()->td_db()->get_binlog_pmc()->set("dc_options_update", log_event_store(dc_options).as_slice().str());
|
|
|
|
}
|
|
|
|
|
|
|
|
DcOptions ConfigManager::load_dc_options_update() {
|
|
|
|
auto log_event_dc_options = G()->td_db()->get_binlog_pmc()->get("dc_options_update");
|
|
|
|
DcOptions dc_options;
|
|
|
|
if (!log_event_dc_options.empty()) {
|
|
|
|
log_event_parse(dc_options, log_event_dc_options).ensure();
|
|
|
|
}
|
|
|
|
return dc_options;
|
|
|
|
}
|
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
Timestamp ConfigManager::load_config_expire_time() {
|
|
|
|
auto expires_in = to_integer<int32>(G()->td_db()->get_binlog_pmc()->get("config_expire")) - Clocks::system();
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
if (expires_in < 0 || expires_in > 60 * 60 /* 1 hour */) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return Timestamp::now();
|
|
|
|
} else {
|
2019-02-10 01:45:15 +01:00
|
|
|
return Timestamp::in(expires_in);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::save_config_expire(Timestamp timestamp) {
|
2020-07-26 14:41:32 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set("config_expire", to_string(static_cast<int>(Clocks::system() + timestamp.in())));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
|
2021-10-05 23:55:22 +02:00
|
|
|
bool is_from_main_dc = G()->net_query_dispatcher().get_main_dc_id().get_value() == config->this_dc_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
LOG(INFO) << to_string(config);
|
2019-12-19 02:58:03 +01:00
|
|
|
auto reload_in = clamp(config->expires_ - config->date_, 60, 86400);
|
2018-12-31 20:04:05 +01:00
|
|
|
save_config_expire(Timestamp::in(reload_in));
|
|
|
|
reload_in -= Random::fast(0, reload_in / 5);
|
|
|
|
if (!is_from_main_dc) {
|
|
|
|
reload_in = 0;
|
|
|
|
}
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = Timestamp::in(reload_in);
|
|
|
|
set_timeout_at(expire_time_.at());
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test";
|
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
Global &options = *G();
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
// Do not save dc_options in config, because it will be interpreted and saved by ConnectionCreator.
|
2023-05-07 00:43:00 +02:00
|
|
|
DcOptions dc_options(config->dc_options_);
|
|
|
|
std::stable_sort(dc_options.dc_options.begin(), dc_options.dc_options.end(),
|
|
|
|
[](const DcOption &lhs, const DcOption &rhs) {
|
|
|
|
if (lhs.get_dc_id() != rhs.get_dc_id()) {
|
|
|
|
return lhs.get_dc_id() < rhs.get_dc_id();
|
|
|
|
}
|
|
|
|
return !lhs.is_ipv6() && rhs.is_ipv6();
|
|
|
|
});
|
|
|
|
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, std::move(dc_options));
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("recent_stickers_limit", config->stickers_recent_limit_);
|
|
|
|
options.set_option_integer("channels_read_media_period", config->channels_read_media_period_);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2023-02-07 12:01:45 +01:00
|
|
|
send_closure(G()->link_manager(), &LinkManager::update_autologin_token, std::move(config->autologin_token_));
|
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_boolean("test_mode", config->test_mode_);
|
|
|
|
options.set_option_integer("forwarded_message_count_max", config->forwarded_count_max_);
|
|
|
|
options.set_option_integer("basic_group_size_max", config->chat_size_max_);
|
|
|
|
options.set_option_integer("supergroup_size_max", config->megagroup_size_max_);
|
|
|
|
if (is_from_main_dc || !options.have_option("expect_blocking")) {
|
|
|
|
options.set_option_boolean("expect_blocking", config->blocked_mode_);
|
2018-05-03 12:18:07 +02:00
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
if (is_from_main_dc || !options.have_option("dc_txt_domain_name")) {
|
|
|
|
options.set_option_string("dc_txt_domain_name", config->dc_txt_domain_name_);
|
2018-06-26 22:46:15 +02:00
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
if (is_from_main_dc || !options.have_option("t_me_url")) {
|
2018-05-17 20:08:51 +02:00
|
|
|
auto url = config->me_url_prefix_;
|
|
|
|
if (!url.empty()) {
|
|
|
|
if (url.back() != '/') {
|
|
|
|
url.push_back('/');
|
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("t_me_url", url);
|
2018-05-17 20:08:51 +02:00
|
|
|
}
|
2018-03-08 16:01:45 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (is_from_main_dc) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("webfile_dc_id", config->webfile_dc_id_);
|
2023-01-25 15:48:04 +01:00
|
|
|
if ((config->flags_ & telegram_api::config::TMP_SESSIONS_MASK) != 0 && config->tmp_sessions_ > 1) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("session_count", config->tmp_sessions_);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("session_count");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-07-03 00:52:43 +02:00
|
|
|
if ((config->flags_ & telegram_api::config::SUGGESTED_LANG_CODE_MASK) != 0) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("suggested_language_pack_id", config->suggested_lang_code_);
|
|
|
|
options.set_option_integer("language_pack_version", config->lang_pack_version_);
|
|
|
|
options.set_option_integer("base_language_pack_version", config->base_lang_pack_version_);
|
2018-07-03 00:52:43 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("suggested_language_pack_id");
|
|
|
|
options.set_option_empty("language_pack_version");
|
|
|
|
options.set_option_empty("base_language_pack_version");
|
2018-07-03 00:52:43 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-03-08 16:01:45 +01:00
|
|
|
if (is_from_main_dc) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("edit_time_limit", config->edit_time_limit_);
|
|
|
|
options.set_option_boolean("revoke_pm_inbox", config->revoke_pm_inbox_);
|
|
|
|
options.set_option_integer("revoke_time_limit", config->revoke_time_limit_);
|
|
|
|
options.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_);
|
2018-03-04 21:50:38 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("rating_e_decay", config->rating_e_decay_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("call_ring_timeout_ms", config->call_ring_timeout_ms_);
|
|
|
|
options.set_option_integer("call_connect_timeout_ms", config->call_connect_timeout_ms_);
|
|
|
|
options.set_option_integer("call_packet_timeout_ms", config->call_packet_timeout_ms_);
|
|
|
|
options.set_option_integer("call_receive_timeout_ms", config->call_receive_timeout_ms_);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("message_text_length_max", clamp(config->message_length_max_, 4096, 1000000));
|
|
|
|
options.set_option_integer("message_caption_length_max", clamp(config->caption_length_max_, 1024, 1000000));
|
2018-06-27 01:28:49 +02:00
|
|
|
|
2018-06-27 01:35:32 +02:00
|
|
|
if (config->gif_search_username_.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("animation_search_bot_username");
|
2018-06-27 01:35:32 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("animation_search_bot_username", config->gif_search_username_);
|
2018-06-27 01:35:32 +02:00
|
|
|
}
|
|
|
|
if (config->venue_search_username_.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("venue_search_bot_username");
|
2018-06-27 01:35:32 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("venue_search_bot_username", config->venue_search_username_);
|
2018-06-27 01:35:32 +02:00
|
|
|
}
|
|
|
|
if (config->img_search_username_.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("photo_search_bot_username");
|
2018-06-27 01:35:32 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("photo_search_bot_username", config->img_search_username_);
|
2018-06-27 01:35:32 +02:00
|
|
|
}
|
|
|
|
|
2019-09-28 04:14:21 +02:00
|
|
|
auto fix_timeout_ms = [](int32 timeout_ms) {
|
|
|
|
return clamp(timeout_ms, 1000, 86400 * 1000);
|
|
|
|
};
|
2018-11-15 23:03:04 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("online_update_period_ms", fix_timeout_ms(config->online_update_period_ms_));
|
2018-11-15 23:03:04 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("online_cloud_timeout_ms", fix_timeout_ms(config->online_cloud_timeout_ms_));
|
|
|
|
options.set_option_integer("notification_cloud_delay_ms", fix_timeout_ms(config->notify_cloud_delay_ms_));
|
|
|
|
options.set_option_integer("notification_default_delay_ms", fix_timeout_ms(config->notify_default_delay_ms_));
|
2018-11-08 14:06:17 +01:00
|
|
|
|
2022-08-22 14:44:38 +02:00
|
|
|
if (is_from_main_dc && !options.have_option("default_reaction_need_sync")) {
|
|
|
|
auto reaction_str = get_message_reaction_string(config->reactions_default_);
|
|
|
|
if (!reaction_str.empty()) {
|
|
|
|
options.set_option_string("default_reaction", reaction_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
// delete outdated options
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("suggested_language_code");
|
|
|
|
options.set_option_empty("chat_big_size");
|
|
|
|
options.set_option_empty("group_size_max");
|
|
|
|
options.set_option_empty("saved_gifs_limit");
|
|
|
|
options.set_option_empty("sessions_count");
|
|
|
|
options.set_option_empty("forwarded_messages_count_max");
|
|
|
|
options.set_option_empty("broadcast_size_max");
|
|
|
|
options.set_option_empty("group_chat_size_max");
|
|
|
|
options.set_option_empty("chat_size_max");
|
|
|
|
options.set_option_empty("megagroup_size_max");
|
|
|
|
options.set_option_empty("offline_blur_timeout_ms");
|
|
|
|
options.set_option_empty("offline_idle_timeout_ms");
|
|
|
|
options.set_option_empty("notify_cloud_delay_ms");
|
|
|
|
options.set_option_empty("notify_default_delay_ms");
|
|
|
|
options.set_option_empty("large_chat_size");
|
2023-02-07 12:01:45 +01:00
|
|
|
options.set_option_empty("calls_enabled");
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
// TODO implement online status updates
|
2022-08-18 20:51:29 +02:00
|
|
|
// options.set_option_integer("offline_blur_timeout_ms", config->offline_blur_timeout_ms_);
|
|
|
|
// options.set_option_integer("offline_idle_timeout_ms", config->offline_idle_timeout_ms_);
|
2018-11-08 14:06:17 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
// options.set_option_integer("push_chat_period_ms", config->push_chat_period_ms_);
|
|
|
|
// options.set_option_integer("push_chat_limit", config->push_chat_limit_);
|
2019-12-19 02:58:03 +01:00
|
|
|
|
|
|
|
if (is_from_main_dc) {
|
2021-10-06 00:17:10 +02:00
|
|
|
reget_app_config(Auto());
|
2022-08-18 20:51:29 +02:00
|
|
|
if (!options.have_option("can_ignore_sensitive_content_restrictions") ||
|
|
|
|
!options.have_option("ignore_sensitive_content_restrictions")) {
|
2019-12-19 21:00:28 +01:00
|
|
|
get_content_settings(Auto());
|
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
if (!options.have_option("archive_and_mute_new_chats_from_unknown_users")) {
|
2020-07-10 19:28:30 +02:00
|
|
|
get_global_privacy_settings(Auto());
|
|
|
|
}
|
2019-12-19 02:58:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &config) {
|
|
|
|
CHECK(config != nullptr);
|
|
|
|
LOG(INFO) << "Receive app config " << to_string(config);
|
|
|
|
|
2021-06-03 22:19:35 +02:00
|
|
|
vector<string> autologin_domains;
|
|
|
|
vector<string> url_auth_domains;
|
2022-10-26 23:57:28 +02:00
|
|
|
vector<string> whitelisted_domains;
|
2021-03-15 23:29:54 +01:00
|
|
|
|
2019-12-19 17:18:42 +01:00
|
|
|
vector<tl_object_ptr<telegram_api::jsonObjectValue>> new_values;
|
2019-12-19 17:58:33 +01:00
|
|
|
string ignored_restriction_reasons;
|
2022-11-02 18:38:52 +01:00
|
|
|
string restriction_add_platforms;
|
2020-04-21 14:45:33 +02:00
|
|
|
vector<string> dice_emojis;
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<string, size_t> dice_emoji_index;
|
|
|
|
FlatHashMap<string, string> dice_emoji_success_value;
|
2021-10-05 22:20:49 +02:00
|
|
|
vector<string> emoji_sounds;
|
2020-05-30 01:42:45 +02:00
|
|
|
string animation_search_provider;
|
|
|
|
string animation_search_emojis;
|
2020-07-11 22:50:21 +02:00
|
|
|
vector<SuggestedAction> suggested_actions;
|
2020-11-28 14:39:56 +01:00
|
|
|
bool can_archive_and_mute_new_chats_from_unknown_users = false;
|
2022-08-31 18:03:26 +02:00
|
|
|
int32 chat_read_mark_expire_period = 0;
|
|
|
|
int32 chat_read_mark_size_threshold = 0;
|
2021-10-13 23:18:44 +02:00
|
|
|
double animated_emoji_zoom = 0.0;
|
2022-08-31 18:03:26 +02:00
|
|
|
int32 reactions_uniq_max = 0;
|
2022-05-23 14:56:31 +02:00
|
|
|
vector<string> premium_features;
|
2022-05-24 00:31:30 +02:00
|
|
|
auto &premium_limit_keys = get_premium_limit_keys();
|
2022-05-24 15:14:25 +02:00
|
|
|
string premium_bot_username;
|
|
|
|
string premium_invoice_slug;
|
2022-06-07 16:22:58 +02:00
|
|
|
bool is_premium_available = false;
|
2022-06-10 12:04:46 +02:00
|
|
|
int32 stickers_premium_by_emoji_num = 0;
|
|
|
|
int32 stickers_normal_by_emoji_per_premium_num = 2;
|
2022-11-25 15:16:37 +01:00
|
|
|
int32 telegram_antispam_group_size_min = 100;
|
2022-12-29 20:26:09 +01:00
|
|
|
int32 topics_pinned_limit = -1;
|
2022-11-29 21:42:29 +01:00
|
|
|
vector<string> fragment_prefixes;
|
2023-03-08 19:13:29 +01:00
|
|
|
bool premium_gift_attach_menu_icon = false;
|
|
|
|
bool premium_gift_text_field_icon = false;
|
2023-04-06 13:58:46 +02:00
|
|
|
int32 dialog_filter_update_period = 300;
|
2023-06-16 13:58:06 +02:00
|
|
|
bool archive_all_stories = false;
|
2023-06-19 18:13:08 +02:00
|
|
|
int32 story_viewers_expire_period = 86400;
|
2023-06-27 16:26:17 +02:00
|
|
|
int64 stories_changelog_user_id = ContactsManager::get_service_notifications_user_id().get();
|
2019-12-19 02:58:03 +01:00
|
|
|
if (config->get_id() == telegram_api::jsonObject::ID) {
|
2019-12-19 17:18:42 +01:00
|
|
|
for (auto &key_value : static_cast<telegram_api::jsonObject *>(config.get())->value_) {
|
|
|
|
Slice key = key_value->key_;
|
|
|
|
telegram_api::JSONValue *value = key_value->value_.get();
|
2022-12-30 22:17:18 +01:00
|
|
|
if (key == "default_emoji_statuses_stickerset_id" || key == "forum_upgrade_participants_min" ||
|
|
|
|
key == "getfile_experimental_params" || key == "message_animated_emoji_max" ||
|
|
|
|
key == "reactions_in_chat_max" || key == "stickers_emoji_cache_time" || key == "test" ||
|
|
|
|
key == "upload_max_fileparts_default" || key == "upload_max_fileparts_premium" ||
|
2022-11-30 10:56:54 +01:00
|
|
|
key == "wallet_blockchain_name" || key == "wallet_config" || key == "wallet_enabled") {
|
2019-12-19 02:58:03 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-12-19 17:58:33 +01:00
|
|
|
if (key == "ignore_restriction_reasons") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto reasons = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &reason : reasons) {
|
2022-04-12 17:01:18 +02:00
|
|
|
auto reason_name = get_json_value_string(std::move(reason), key);
|
2021-09-03 17:14:15 +02:00
|
|
|
if (!reason_name.empty() && reason_name.find(',') == string::npos) {
|
|
|
|
if (!ignored_restriction_reasons.empty()) {
|
|
|
|
ignored_restriction_reasons += ',';
|
2019-12-19 17:58:33 +01:00
|
|
|
}
|
2021-09-03 17:14:15 +02:00
|
|
|
ignored_restriction_reasons += reason_name;
|
2019-12-19 17:58:33 +01:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive unexpected restriction reason " << reason_name;
|
2019-12-19 17:58:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected ignore_restriction_reasons " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-02 18:38:52 +01:00
|
|
|
if (key == "restriction_add_platforms") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto platforms = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &platform : platforms) {
|
|
|
|
auto platform_name = get_json_value_string(std::move(platform), key);
|
|
|
|
if (!platform_name.empty() && platform_name.find(',') == string::npos) {
|
|
|
|
if (!restriction_add_platforms.empty()) {
|
|
|
|
restriction_add_platforms += ',';
|
|
|
|
}
|
|
|
|
restriction_add_platforms += platform_name;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected restriction platform " << platform_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected restriction_add_platforms " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-13 23:18:44 +02:00
|
|
|
if (key == "emojies_animated_zoom") {
|
2022-04-12 17:01:18 +02:00
|
|
|
animated_emoji_zoom = get_json_value_double(std::move(key_value->value_), key);
|
2021-10-13 23:18:44 +02:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-19 10:17:51 +02:00
|
|
|
if (key == "emojies_send_dice") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto emojis = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &emoji : emojis) {
|
2022-04-12 17:01:18 +02:00
|
|
|
auto emoji_text = get_json_value_string(std::move(emoji), key);
|
2021-09-03 17:14:15 +02:00
|
|
|
if (!emoji_text.empty()) {
|
|
|
|
dice_emoji_index[emoji_text] = dice_emojis.size();
|
|
|
|
dice_emojis.push_back(emoji_text);
|
2020-04-19 10:17:51 +02:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive empty dice emoji";
|
2020-04-19 10:17:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected emojies_send_dice " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-21 13:51:46 +02:00
|
|
|
if (key == "emojies_send_dice_success") {
|
2020-04-21 18:08:01 +02:00
|
|
|
if (value->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
auto success_values = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
2020-04-21 13:51:46 +02:00
|
|
|
for (auto &success_value : success_values) {
|
|
|
|
CHECK(success_value != nullptr);
|
2022-02-09 22:59:52 +01:00
|
|
|
if (!success_value->key_.empty() && success_value->value_->get_id() == telegram_api::jsonObject::ID) {
|
2020-04-21 18:08:01 +02:00
|
|
|
int32 dice_value = -1;
|
|
|
|
int32 frame_start = -1;
|
|
|
|
for (auto &dice_key_value :
|
|
|
|
static_cast<telegram_api::jsonObject *>(success_value->value_.get())->value_) {
|
|
|
|
if (dice_key_value->value_->get_id() != telegram_api::jsonNumber::ID) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-03 16:54:04 +02:00
|
|
|
auto current_value = get_json_value_int(std::move(dice_key_value->value_), Slice());
|
2020-04-21 18:08:01 +02:00
|
|
|
if (dice_key_value->key_ == "value") {
|
|
|
|
dice_value = current_value;
|
|
|
|
}
|
|
|
|
if (dice_key_value->key_ == "frame_start") {
|
|
|
|
frame_start = current_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dice_value < 0 || frame_start < 0) {
|
|
|
|
LOG(ERROR) << "Receive unexpected dice success value " << to_string(success_value);
|
|
|
|
} else {
|
|
|
|
dice_emoji_success_value[success_value->key_] = PSTRING() << dice_value << ':' << frame_start;
|
2020-04-21 13:51:46 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected dice success value " << to_string(success_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected emojies_send_dice_success " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-05 22:20:49 +02:00
|
|
|
if (key == "emojies_sounds") {
|
|
|
|
if (value->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
auto sounds = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
|
|
|
for (auto &sound : sounds) {
|
|
|
|
CHECK(sound != nullptr);
|
|
|
|
if (sound->value_->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
string id;
|
|
|
|
string access_hash;
|
|
|
|
string file_reference_base64;
|
|
|
|
for (auto &sound_key_value : static_cast<telegram_api::jsonObject *>(sound->value_.get())->value_) {
|
|
|
|
if (sound_key_value->value_->get_id() != telegram_api::jsonString::ID) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto current_value = get_json_value_string(std::move(sound_key_value->value_), Slice());
|
|
|
|
if (sound_key_value->key_ == "id") {
|
|
|
|
id = std::move(current_value);
|
2021-11-10 18:05:41 +01:00
|
|
|
} else if (sound_key_value->key_ == "access_hash") {
|
2021-10-05 22:20:49 +02:00
|
|
|
access_hash = std::move(current_value);
|
2021-11-10 18:05:41 +01:00
|
|
|
} else if (sound_key_value->key_ == "file_reference_base64") {
|
2021-10-05 22:20:49 +02:00
|
|
|
file_reference_base64 = std::move(current_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (to_integer_safe<int64>(id).is_error() || to_integer_safe<int64>(access_hash).is_error() ||
|
|
|
|
!is_base64url(file_reference_base64) || !is_emoji(sound->key_)) {
|
|
|
|
LOG(ERROR) << "Receive unexpected sound value " << to_string(sound);
|
|
|
|
} else {
|
|
|
|
emoji_sounds.push_back(sound->key_);
|
|
|
|
emoji_sounds.push_back(PSTRING() << id << ':' << access_hash << ':' << file_reference_base64);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected emoji sound " << to_string(sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected emojies_sounds " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-30 01:42:45 +02:00
|
|
|
if (key == "gif_search_branding") {
|
2022-04-12 17:01:18 +02:00
|
|
|
animation_search_provider = get_json_value_string(std::move(key_value->value_), key);
|
2020-05-30 01:42:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "gif_search_emojies") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto emojis = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &emoji : emojis) {
|
2022-04-12 17:01:18 +02:00
|
|
|
auto emoji_str = get_json_value_string(std::move(emoji), key);
|
2021-09-03 17:14:15 +02:00
|
|
|
if (!emoji_str.empty() && emoji_str.find(',') == string::npos) {
|
|
|
|
if (!animation_search_emojis.empty()) {
|
|
|
|
animation_search_emojis += ',';
|
2020-05-30 01:42:45 +02:00
|
|
|
}
|
2021-09-03 17:14:15 +02:00
|
|
|
animation_search_emojis += emoji_str;
|
2020-05-30 01:42:45 +02:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive unexpected animation search emoji " << emoji_str;
|
2020-05-30 01:42:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected gif_search_emojies " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-11 22:50:21 +02:00
|
|
|
if (key == "pending_suggestions") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto actions = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
2023-01-17 11:22:21 +01:00
|
|
|
const bool archive_and_mute = G()->get_option_boolean("archive_and_mute_new_chats_from_unknown_users");
|
|
|
|
auto otherwise_relogin_days = G()->get_option_integer("otherwise_relogin_days");
|
2020-07-11 22:50:21 +02:00
|
|
|
for (auto &action : actions) {
|
2022-04-12 17:01:18 +02:00
|
|
|
auto action_str = get_json_value_string(std::move(action), key);
|
2021-09-03 17:14:15 +02:00
|
|
|
SuggestedAction suggested_action(action_str);
|
|
|
|
if (!suggested_action.is_empty()) {
|
|
|
|
if (archive_and_mute &&
|
|
|
|
suggested_action == SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats}) {
|
|
|
|
LOG(INFO) << "Skip EnableArchiveAndMuteNewChats suggested action";
|
2023-01-17 11:22:21 +01:00
|
|
|
} else if (otherwise_relogin_days > 0 &&
|
|
|
|
suggested_action == SuggestedAction{SuggestedAction::Type::SetPassword}) {
|
|
|
|
LOG(INFO) << "Skip SetPassword suggested action";
|
2020-07-11 22:50:21 +02:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
suggested_actions.push_back(suggested_action);
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive unsupported suggested action " << action_str;
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected pending_suggestions " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-28 14:39:56 +01:00
|
|
|
if (key == "autoarchive_setting_available") {
|
2022-04-12 17:01:18 +02:00
|
|
|
can_archive_and_mute_new_chats_from_unknown_users = get_json_value_bool(std::move(key_value->value_), key);
|
2020-11-28 14:39:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-02-04 12:36:11 +01:00
|
|
|
if (key == "autologin_domains") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &domain : domains) {
|
2022-04-12 17:01:18 +02:00
|
|
|
autologin_domains.push_back(get_json_value_string(std::move(domain), key));
|
2021-02-04 12:36:11 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected autologin_domains " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-15 23:29:54 +01:00
|
|
|
if (key == "url_auth_domains") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &domain : domains) {
|
2022-10-26 23:57:28 +02:00
|
|
|
url_auth_domains.push_back(get_json_value_string(std::move(domain), key));
|
2021-03-15 23:29:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected url_auth_domains " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2022-10-26 23:57:28 +02:00
|
|
|
if (key == "whitelisted_domains") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &domain : domains) {
|
|
|
|
whitelisted_domains.push_back(get_json_value_string(std::move(domain), key));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected whitelisted_domains " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-07-28 05:15:57 +02:00
|
|
|
if (key == "round_video_encoding") {
|
|
|
|
if (value->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
auto video_note_settings = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
|
|
|
for (auto &video_note_setting : video_note_settings) {
|
|
|
|
CHECK(video_note_setting != nullptr);
|
|
|
|
if (video_note_setting->key_ != "diameter" && video_note_setting->key_ != "video_bitrate" &&
|
2021-07-29 22:39:07 +02:00
|
|
|
video_note_setting->key_ != "audio_bitrate" && video_note_setting->key_ != "max_size") {
|
2021-07-28 05:15:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (video_note_setting->value_->get_id() == telegram_api::jsonNumber::ID) {
|
2021-09-03 16:54:04 +02:00
|
|
|
auto setting_value = get_json_value_int(std::move(video_note_setting->value_), Slice());
|
2021-07-29 12:02:38 +02:00
|
|
|
if (setting_value > 0) {
|
2021-07-28 05:15:57 +02:00
|
|
|
if (video_note_setting->key_ == "diameter") {
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("suggested_video_note_length", setting_value);
|
2021-07-28 05:15:57 +02:00
|
|
|
}
|
|
|
|
if (video_note_setting->key_ == "video_bitrate") {
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("suggested_video_note_video_bitrate", setting_value);
|
2021-07-28 05:15:57 +02:00
|
|
|
}
|
|
|
|
if (video_note_setting->key_ == "audio_bitrate") {
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("suggested_video_note_audio_bitrate", setting_value);
|
2021-07-28 05:15:57 +02:00
|
|
|
}
|
2021-07-29 22:39:07 +02:00
|
|
|
if (video_note_setting->key_ == "max_size") {
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("video_note_size_max", setting_value);
|
2021-07-29 22:39:07 +02:00
|
|
|
}
|
2021-07-28 05:15:57 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected video note setting " << to_string(video_note_setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected round_video_encoding " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-03 18:06:24 +02:00
|
|
|
if (key == "chat_read_mark_expire_period") {
|
2022-04-12 17:01:18 +02:00
|
|
|
chat_read_mark_expire_period = get_json_value_int(std::move(key_value->value_), key);
|
2021-09-03 18:06:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "chat_read_mark_size_threshold") {
|
2022-04-12 17:01:18 +02:00
|
|
|
chat_read_mark_size_threshold = get_json_value_int(std::move(key_value->value_), key);
|
2021-09-03 18:06:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-25 20:53:51 +01:00
|
|
|
if (key == "reactions_uniq_max") {
|
2022-04-12 17:01:18 +02:00
|
|
|
reactions_uniq_max = get_json_value_int(std::move(key_value->value_), key);
|
2022-01-25 20:53:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
2022-04-12 17:15:45 +02:00
|
|
|
if (key == "ringtone_duration_max") {
|
|
|
|
auto setting_value = get_json_value_int(std::move(key_value->value_), key);
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("notification_sound_duration_max", setting_value);
|
2022-04-12 17:15:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "ringtone_size_max") {
|
|
|
|
auto setting_value = get_json_value_int(std::move(key_value->value_), key);
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("notification_sound_size_max", setting_value);
|
2022-04-12 17:15:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "ringtone_saved_count_max") {
|
|
|
|
auto setting_value = get_json_value_int(std::move(key_value->value_), key);
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer("notification_sound_count_max", setting_value);
|
2022-04-12 17:15:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-23 14:56:31 +02:00
|
|
|
if (key == "premium_promo_order") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto features = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &feature : features) {
|
|
|
|
auto premium_feature = get_json_value_string(std::move(feature), key);
|
|
|
|
if (!td::contains(premium_feature, ',')) {
|
|
|
|
premium_features.push_back(std::move(premium_feature));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected premium_promo_order " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-23 16:47:06 +02:00
|
|
|
bool is_premium_limit_key = false;
|
|
|
|
for (auto premium_limit_key : premium_limit_keys) {
|
2022-05-24 00:31:30 +02:00
|
|
|
if (begins_with(key, premium_limit_key)) {
|
|
|
|
auto suffix = key.substr(premium_limit_key.size());
|
2022-05-24 01:59:11 +02:00
|
|
|
if (suffix == "_limit_default" || suffix == "_limit_premium") {
|
2022-05-24 00:31:30 +02:00
|
|
|
auto setting_value = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
if (setting_value > 0) {
|
2022-08-17 15:11:13 +02:00
|
|
|
G()->set_option_integer(key, setting_value);
|
2022-05-24 00:31:30 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive invalid value " << setting_value << " for " << key;
|
|
|
|
}
|
|
|
|
is_premium_limit_key = true;
|
|
|
|
break;
|
2022-05-23 16:47:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_premium_limit_key) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-24 15:14:25 +02:00
|
|
|
if (key == "premium_bot_username") {
|
|
|
|
premium_bot_username = get_json_value_string(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "premium_invoice_slug") {
|
|
|
|
premium_invoice_slug = get_json_value_string(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-06 14:01:58 +02:00
|
|
|
if (key == "premium_purchase_blocked") {
|
2022-06-13 15:19:14 +02:00
|
|
|
is_premium_available = !get_json_value_bool(std::move(key_value->value_), key);
|
2022-06-06 14:01:58 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-06-10 12:04:46 +02:00
|
|
|
if (key == "stickers_premium_by_emoji_num") {
|
|
|
|
stickers_premium_by_emoji_num = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "stickers_normal_by_emoji_per_premium_num") {
|
|
|
|
stickers_normal_by_emoji_per_premium_num = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2022-09-09 17:24:42 +02:00
|
|
|
if (key == "reactions_user_max_default" || key == "reactions_user_max_premium") {
|
|
|
|
auto setting_value = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
G()->set_option_integer(key, setting_value);
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-25 14:50:16 +01:00
|
|
|
if (key == "telegram_antispam_user_id") {
|
|
|
|
auto setting_value = get_json_value_long(std::move(key_value->value_), key);
|
2022-11-30 11:36:44 +01:00
|
|
|
G()->set_option_integer("anti_spam_bot_user_id", setting_value);
|
2022-11-25 14:50:16 +01:00
|
|
|
continue;
|
|
|
|
}
|
2022-11-25 15:16:37 +01:00
|
|
|
if (key == "telegram_antispam_group_size_min") {
|
|
|
|
telegram_antispam_group_size_min = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-29 21:42:29 +01:00
|
|
|
if (key == "fragment_prefixes") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto prefixes = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &prefix : prefixes) {
|
|
|
|
auto prefix_text = get_json_value_string(std::move(prefix), key);
|
|
|
|
clean_phone_number(prefix_text);
|
|
|
|
if (!prefix_text.empty()) {
|
|
|
|
fragment_prefixes.push_back(prefix_text);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive an invalid Fragment prefix";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected fragment_prefixes " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2022-12-20 09:04:00 +01:00
|
|
|
if (key == "hidden_members_group_size_min") {
|
|
|
|
auto setting_value = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
G()->set_option_integer("hidden_members_group_size_min", setting_value);
|
|
|
|
continue;
|
|
|
|
}
|
2022-12-29 20:26:09 +01:00
|
|
|
if (key == "topics_pinned_limit") {
|
|
|
|
topics_pinned_limit = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2023-03-08 19:13:29 +01:00
|
|
|
if (key == "premium_gift_attach_menu_icon") {
|
|
|
|
premium_gift_attach_menu_icon = get_json_value_bool(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "premium_gift_text_field_icon") {
|
|
|
|
premium_gift_text_field_icon = get_json_value_bool(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2023-04-06 13:58:46 +02:00
|
|
|
if (key == "chatlist_update_period") {
|
|
|
|
dialog_filter_update_period = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2023-06-16 13:58:06 +02:00
|
|
|
if (key == "stories_all_hidden") {
|
|
|
|
archive_all_stories = get_json_value_bool(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2023-06-19 18:13:08 +02:00
|
|
|
if (key == "story_viewers_expire_period") {
|
|
|
|
story_viewers_expire_period = get_json_value_int(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2023-06-27 16:26:17 +02:00
|
|
|
if (key == "stories_changelog_user_id") {
|
|
|
|
stories_changelog_user_id = get_json_value_long(std::move(key_value->value_), key);
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-19 02:58:03 +01:00
|
|
|
|
2019-12-19 17:18:42 +01:00
|
|
|
new_values.push_back(std::move(key_value));
|
2019-12-19 02:58:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive wrong app config " << to_string(config);
|
|
|
|
}
|
2019-12-19 17:18:42 +01:00
|
|
|
config = make_tl_object<telegram_api::jsonObject>(std::move(new_values));
|
|
|
|
|
2023-02-07 12:01:45 +01:00
|
|
|
send_closure(G()->link_manager(), &LinkManager::update_autologin_domains, std::move(autologin_domains),
|
|
|
|
std::move(url_auth_domains), std::move(whitelisted_domains));
|
2021-02-04 23:40:53 +01:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
Global &options = *G();
|
2019-12-20 14:11:58 +01:00
|
|
|
|
2019-12-19 17:58:33 +01:00
|
|
|
if (ignored_restriction_reasons.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("ignored_restriction_reasons");
|
2019-12-19 21:00:28 +01:00
|
|
|
|
2022-08-25 19:39:44 +02:00
|
|
|
if (options.get_option_boolean("ignore_sensitive_content_restrictions", true) ||
|
|
|
|
options.get_option_boolean("can_ignore_sensitive_content_restrictions", true)) {
|
2019-12-19 21:00:28 +01:00
|
|
|
get_content_settings(Auto());
|
|
|
|
}
|
2019-12-19 17:58:33 +01:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("ignored_restriction_reasons", ignored_restriction_reasons);
|
2019-12-19 21:00:28 +01:00
|
|
|
|
2022-08-25 19:39:44 +02:00
|
|
|
if (!options.get_option_boolean("can_ignore_sensitive_content_restrictions") ||
|
|
|
|
!options.get_option_boolean("ignore_sensitive_content_restrictions")) {
|
2019-12-19 21:00:28 +01:00
|
|
|
get_content_settings(Auto());
|
|
|
|
}
|
2019-12-19 17:58:33 +01:00
|
|
|
}
|
2022-11-02 18:38:52 +01:00
|
|
|
if (restriction_add_platforms.empty()) {
|
|
|
|
options.set_option_empty("restriction_add_platforms");
|
|
|
|
} else {
|
|
|
|
options.set_option_string("restriction_add_platforms", restriction_add_platforms);
|
|
|
|
}
|
2020-04-19 10:17:51 +02:00
|
|
|
|
|
|
|
if (!dice_emojis.empty()) {
|
2020-04-21 18:08:01 +02:00
|
|
|
vector<string> dice_success_values(dice_emojis.size());
|
|
|
|
for (auto &it : dice_emoji_success_value) {
|
2022-02-03 14:24:09 +01:00
|
|
|
auto dice_emoji_it = dice_emoji_index.find(it.first);
|
|
|
|
if (dice_emoji_it == dice_emoji_index.end()) {
|
2020-04-21 18:08:01 +02:00
|
|
|
LOG(ERROR) << "Can't find emoji " << it.first;
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-03 14:24:09 +01:00
|
|
|
dice_success_values[dice_emoji_it->second] = it.second;
|
2020-04-21 18:08:01 +02:00
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("dice_success_values", implode(dice_success_values, ','));
|
|
|
|
options.set_option_string("dice_emojis", implode(dice_emojis, '\x01'));
|
2020-04-21 13:51:46 +02:00
|
|
|
}
|
2020-05-30 01:42:45 +02:00
|
|
|
|
2022-11-29 21:42:29 +01:00
|
|
|
options.set_option_string("fragment_prefixes", implode(fragment_prefixes, ','));
|
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("emoji_sounds", implode(emoji_sounds, ','));
|
2021-10-05 22:20:49 +02:00
|
|
|
|
2021-10-13 23:18:44 +02:00
|
|
|
if (animated_emoji_zoom <= 0 || animated_emoji_zoom > 2.0) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("animated_emoji_zoom");
|
2021-10-13 23:18:44 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("animated_emoji_zoom", static_cast<int64>(animated_emoji_zoom * 1e9));
|
2021-10-13 23:18:44 +02:00
|
|
|
}
|
2020-05-30 01:42:45 +02:00
|
|
|
if (animation_search_provider.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("animation_search_provider");
|
2020-05-30 01:42:45 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("animation_search_provider", animation_search_provider);
|
2020-05-30 01:42:45 +02:00
|
|
|
}
|
|
|
|
if (animation_search_emojis.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("animation_search_emojis");
|
2020-05-30 01:42:45 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("animation_search_emojis", animation_search_emojis);
|
2020-05-30 01:42:45 +02:00
|
|
|
}
|
2020-11-28 14:39:56 +01:00
|
|
|
if (!can_archive_and_mute_new_chats_from_unknown_users) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("can_archive_and_mute_new_chats_from_unknown_users");
|
2020-11-28 14:39:56 +01:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_boolean("can_archive_and_mute_new_chats_from_unknown_users",
|
|
|
|
can_archive_and_mute_new_chats_from_unknown_users);
|
2020-11-28 14:39:56 +01:00
|
|
|
}
|
2021-09-03 18:06:24 +02:00
|
|
|
if (chat_read_mark_expire_period <= 0) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("chat_read_mark_expire_period");
|
2021-09-03 18:06:24 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("chat_read_mark_expire_period", chat_read_mark_expire_period);
|
2021-09-03 18:06:24 +02:00
|
|
|
}
|
|
|
|
if (chat_read_mark_size_threshold <= 0) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("chat_read_mark_size_threshold");
|
2021-09-03 18:06:24 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("chat_read_mark_size_threshold", chat_read_mark_size_threshold);
|
2021-09-03 18:06:24 +02:00
|
|
|
}
|
2022-01-25 20:53:51 +01:00
|
|
|
if (reactions_uniq_max <= 0 || reactions_uniq_max == 11) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("reactions_uniq_max");
|
2022-01-25 20:53:51 +01:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("reactions_uniq_max", reactions_uniq_max);
|
2022-01-25 20:53:51 +01:00
|
|
|
}
|
2022-11-25 15:16:37 +01:00
|
|
|
if (telegram_antispam_group_size_min >= 0) {
|
|
|
|
options.set_option_integer("aggressive_anti_spam_supergroup_member_count_min", telegram_antispam_group_size_min);
|
|
|
|
}
|
2023-04-06 13:58:46 +02:00
|
|
|
if (dialog_filter_update_period > 0) {
|
|
|
|
options.set_option_integer("chat_folder_new_chats_update_period", dialog_filter_update_period);
|
|
|
|
}
|
2020-06-08 01:12:57 +02:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
bool is_premium = options.get_option_boolean("is_premium");
|
2023-02-07 12:01:45 +01:00
|
|
|
if (is_premium) {
|
2023-04-03 16:28:51 +02:00
|
|
|
options.set_option_integer("chat_folder_count_max", options.get_option_integer("dialog_filters_limit_premium", 20));
|
|
|
|
options.set_option_integer("chat_folder_chosen_chat_count_max",
|
2023-02-07 12:01:45 +01:00
|
|
|
options.get_option_integer("dialog_filters_chats_limit_premium", 200));
|
|
|
|
options.set_option_integer("bio_length_max", options.get_option_integer("about_length_limit_premium", 140));
|
|
|
|
options.set_option_integer("saved_animations_limit", options.get_option_integer("saved_gifs_limit_premium", 400));
|
|
|
|
options.set_option_integer("favorite_stickers_limit",
|
|
|
|
options.get_option_integer("stickers_faved_limit_premium", 10));
|
|
|
|
options.set_option_integer("pinned_chat_count_max",
|
|
|
|
options.get_option_integer("dialogs_pinned_limit_premium", 200));
|
|
|
|
options.set_option_integer("pinned_archived_chat_count_max",
|
|
|
|
options.get_option_integer("dialogs_folder_pinned_limit_premium", 200));
|
2023-04-10 11:46:16 +02:00
|
|
|
options.set_option_integer("chat_folder_invite_link_count_max",
|
|
|
|
options.get_option_integer("chatlist_invites_limit_premium", 20));
|
|
|
|
options.set_option_integer("added_shareable_chat_folder_count_max",
|
|
|
|
options.get_option_integer("chatlist_invites_limit_premium", 20));
|
2023-02-07 12:01:45 +01:00
|
|
|
} else {
|
2023-04-03 16:28:51 +02:00
|
|
|
options.set_option_integer("chat_folder_count_max", options.get_option_integer("dialog_filters_limit_default", 10));
|
|
|
|
options.set_option_integer("chat_folder_chosen_chat_count_max",
|
2023-02-07 12:01:45 +01:00
|
|
|
options.get_option_integer("dialog_filters_chats_limit_default", 100));
|
|
|
|
options.set_option_integer("bio_length_max", options.get_option_integer("about_length_limit_default", 70));
|
|
|
|
options.set_option_integer("saved_animations_limit", options.get_option_integer("saved_gifs_limit_default", 200));
|
|
|
|
options.set_option_integer("favorite_stickers_limit",
|
|
|
|
options.get_option_integer("stickers_faved_limit_default", 5));
|
|
|
|
options.set_option_integer("pinned_chat_count_max",
|
|
|
|
options.get_option_integer("dialogs_pinned_limit_default", 100));
|
|
|
|
options.set_option_integer("pinned_archived_chat_count_max",
|
|
|
|
options.get_option_integer("dialogs_folder_pinned_limit_default", 100));
|
2023-04-10 11:46:16 +02:00
|
|
|
options.set_option_integer("chat_folder_invite_link_count_max",
|
|
|
|
options.get_option_integer("chatlist_invites_limit_default", 3));
|
|
|
|
options.set_option_integer("added_shareable_chat_folder_count_max",
|
|
|
|
options.get_option_integer("chatlist_invites_limit_default", 2));
|
2023-02-07 12:01:45 +01:00
|
|
|
}
|
2022-05-30 02:23:21 +02:00
|
|
|
|
2022-06-06 14:01:58 +02:00
|
|
|
if (!is_premium_available) {
|
|
|
|
premium_bot_username.clear(); // just in case
|
|
|
|
premium_invoice_slug.clear(); // just in case
|
|
|
|
premium_features.clear(); // just in case
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("is_premium_available");
|
2022-06-06 14:01:58 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_boolean("is_premium_available", is_premium_available);
|
2022-06-06 14:01:58 +02:00
|
|
|
}
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("premium_features", implode(premium_features, ','));
|
2022-05-24 15:14:25 +02:00
|
|
|
if (premium_bot_username.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("premium_bot_username");
|
2022-05-24 15:14:25 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("premium_bot_username", premium_bot_username);
|
2022-05-24 15:14:25 +02:00
|
|
|
}
|
|
|
|
if (premium_invoice_slug.empty()) {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("premium_invoice_slug");
|
2022-05-24 15:14:25 +02:00
|
|
|
} else {
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_string("premium_invoice_slug", premium_invoice_slug);
|
2022-05-24 15:14:25 +02:00
|
|
|
}
|
2022-12-29 20:26:09 +01:00
|
|
|
if (topics_pinned_limit >= 0) {
|
|
|
|
options.set_option_integer("pinned_forum_topic_count_max", topics_pinned_limit);
|
|
|
|
} else {
|
|
|
|
options.set_option_empty("pinned_forum_topic_count_max");
|
|
|
|
}
|
2022-05-23 14:56:31 +02:00
|
|
|
|
2023-03-08 19:13:29 +01:00
|
|
|
if (premium_gift_attach_menu_icon) {
|
|
|
|
options.set_option_boolean("gift_premium_from_attachment_menu", premium_gift_attach_menu_icon);
|
|
|
|
} else {
|
|
|
|
options.set_option_empty("gift_premium_from_attachment_menu");
|
|
|
|
}
|
|
|
|
if (premium_gift_text_field_icon) {
|
|
|
|
options.set_option_boolean("gift_premium_from_input_field", premium_gift_text_field_icon);
|
|
|
|
} else {
|
|
|
|
options.set_option_empty("gift_premium_from_input_field");
|
|
|
|
}
|
2023-06-27 16:26:17 +02:00
|
|
|
if (stories_changelog_user_id != ContactsManager::get_service_notifications_user_id().get()) {
|
|
|
|
options.set_option_integer("stories_changelog_user_id", stories_changelog_user_id);
|
|
|
|
} else {
|
|
|
|
options.set_option_empty("stories_changelog_user_id");
|
|
|
|
}
|
2023-03-08 19:13:29 +01:00
|
|
|
|
2023-06-19 18:13:08 +02:00
|
|
|
if (story_viewers_expire_period >= 0) {
|
|
|
|
options.set_option_integer("story_viewers_expire_period", story_viewers_expire_period);
|
|
|
|
}
|
|
|
|
|
2023-06-16 16:55:54 +02:00
|
|
|
if (!options.get_option_boolean("need_synchronize_archive_all_stories")) {
|
|
|
|
options.set_option_boolean("archive_all_stories", archive_all_stories);
|
|
|
|
}
|
2023-06-16 13:58:06 +02:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_integer("stickers_premium_by_emoji_num", stickers_premium_by_emoji_num);
|
|
|
|
options.set_option_integer("stickers_normal_by_emoji_per_premium_num", stickers_normal_by_emoji_per_premium_num);
|
2022-06-10 12:04:46 +02:00
|
|
|
|
2022-08-18 20:51:29 +02:00
|
|
|
options.set_option_empty("default_ton_blockchain_config");
|
|
|
|
options.set_option_empty("default_ton_blockchain_name");
|
2020-07-11 22:50:21 +02:00
|
|
|
|
2020-07-12 14:04:49 +02:00
|
|
|
// do not update suggested actions while changing content settings or dismissing an action
|
|
|
|
if (!is_set_content_settings_request_sent_ && dismiss_suggested_action_request_count_ == 0) {
|
2021-02-22 16:25:49 +01:00
|
|
|
update_suggested_actions(suggested_actions_, std::move(suggested_actions));
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
|
|
|
if (!suggested_actions_.empty()) {
|
2023-01-17 11:22:21 +01:00
|
|
|
updates.push_back(get_update_suggested_actions_object(suggested_actions_, {}, "get_current_state"));
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:12:32 +01:00
|
|
|
constexpr uint64 ConfigManager::REFCNT_TOKEN;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|