Add get_json_value_bool helper function.

This commit is contained in:
levlam 2021-09-03 18:17:11 +03:00
parent 9a6e8cad9e
commit 9ebeafbb5b
3 changed files with 13 additions and 6 deletions

View File

@ -1606,12 +1606,8 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
continue;
}
if (key == "autoarchive_setting_available") {
if (value->get_id() == telegram_api::jsonBool::ID) {
can_archive_and_mute_new_chats_from_unknown_users =
std::move(static_cast<telegram_api::jsonBool *>(value)->value_);
} else {
LOG(ERROR) << "Receive unexpected autoarchive_setting_available " << to_string(*value);
}
get_json_value_bool(std::move(key_value->value_), "autoarchive_setting_available");
continue;
}
if (key == "autologin_token") {

View File

@ -199,6 +199,15 @@ string get_json_string(const td_api::JsonValue *json_value) {
return json_encode<string>(JsonableJsonValue(json_value));
}
bool get_json_value_bool(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name) {
CHECK(json_value != nullptr);
if (json_value->get_id() == telegram_api::jsonBool::ID) {
return static_cast<const telegram_api::jsonBool *>(json_value.get())->value_;
}
LOG(ERROR) << "Expected Boolean as " << name << ", but found " << to_string(json_value);
return false;
}
int32 get_json_value_int(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name) {
CHECK(json_value != nullptr);
if (json_value->get_id() == telegram_api::jsonNumber::ID) {

View File

@ -26,6 +26,8 @@ tl_object_ptr<telegram_api::JSONValue> convert_json_value(td_api::object_ptr<td_
string get_json_string(const td_api::JsonValue *json_value);
bool get_json_value_bool(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name);
int32 get_json_value_int(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name);
string get_json_value_string(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name);