Use JsonOnject::extract_ if possible.
This commit is contained in:
parent
7a80136478
commit
3303c659bf
@ -298,7 +298,7 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<Simpl
|
||||
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));
|
||||
TRY_RESULT(answer, answer_object.extract_required_field("Answer", JsonValue::Type::Array));
|
||||
return get_data(answer);
|
||||
}
|
||||
};
|
||||
@ -383,7 +383,7 @@ ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> prom
|
||||
return Status::Error("Expected JSON object");
|
||||
}
|
||||
auto &json_object = json.get_object();
|
||||
TRY_RESULT(data, get_json_object_field(json_object, "data", JsonValue::Type::Object, false));
|
||||
TRY_RESULT(data, json_object.extract_required_field("data", JsonValue::Type::Object));
|
||||
auto &data_object = data.get_object();
|
||||
TRY_RESULT(config, data_object.get_required_string_field("stringValue"));
|
||||
return std::move(config);
|
||||
|
@ -3019,7 +3019,7 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
|
||||
if (sent_date - 28 * 86400 <= date && date <= sent_date + 5) {
|
||||
sent_date = date;
|
||||
}
|
||||
TRY_RESULT(data_data, get_json_object_field(data, "data", JsonValue::Type::Object, false));
|
||||
TRY_RESULT(data_data, data.extract_required_field("data", JsonValue::Type::Object));
|
||||
data = std::move(data_data.get_object());
|
||||
}
|
||||
|
||||
@ -3388,14 +3388,14 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
|
||||
!td_->contacts_manager_->have_user_force(sender_user_id, "process_push_notification_payload")) {
|
||||
int64 sender_access_hash = -1;
|
||||
telegram_api::object_ptr<telegram_api::UserProfilePhoto> sender_photo;
|
||||
TRY_RESULT(mtpeer, get_json_object_field(custom, "mtpeer", JsonValue::Type::Object));
|
||||
TRY_RESULT(mtpeer, custom.extract_optional_field("mtpeer", JsonValue::Type::Object));
|
||||
if (mtpeer.type() != JsonValue::Type::Null) {
|
||||
auto &mtpeer_object = mtpeer.get_object();
|
||||
TRY_RESULT(ah, mtpeer_object.get_optional_string_field("ah"));
|
||||
if (!ah.empty()) {
|
||||
TRY_RESULT_ASSIGN(sender_access_hash, to_integer_safe<int64>(ah));
|
||||
}
|
||||
TRY_RESULT(ph, get_json_object_field(mtpeer_object, "ph", JsonValue::Type::Object));
|
||||
TRY_RESULT(ph, mtpeer_object.extract_optional_field("ph", JsonValue::Type::Object));
|
||||
if (ph.type() != JsonValue::Type::Null) {
|
||||
// TODO parse sender photo
|
||||
}
|
||||
@ -3964,7 +3964,7 @@ Result<int64> NotificationManager::get_push_receiver_id(string payload) {
|
||||
|
||||
auto data = std::move(json_value.get_object());
|
||||
if (data.has_field("data")) {
|
||||
auto r_data_data = get_json_object_field(data, "data", JsonValue::Type::Object, false);
|
||||
auto r_data_data = data.extract_required_field("data", JsonValue::Type::Object);
|
||||
if (r_data_data.is_error()) {
|
||||
return Status::Error(400, r_data_data.error().message());
|
||||
}
|
||||
|
@ -7103,7 +7103,7 @@ Status StickersManager::on_animated_emoji_message_clicked(string &&emoji, FullMe
|
||||
if (version != 1) {
|
||||
return Status::OK();
|
||||
}
|
||||
TRY_RESULT(array_value, get_json_object_field(object, "a", JsonValue::Type::Array, false));
|
||||
TRY_RESULT(array_value, object.extract_required_field("a", JsonValue::Type::Array));
|
||||
auto &array = array_value.get_array();
|
||||
if (array.size() > 20) {
|
||||
return Status::Error("Click array is too big");
|
||||
|
@ -161,7 +161,7 @@ std::enable_if_t<!std::is_constructible<T>::value, Status> from_json(tl_object_p
|
||||
}
|
||||
|
||||
auto &object = from.get_object();
|
||||
TRY_RESULT(constructor_value, get_json_object_field(object, "@type", JsonValue::Type::Null, false));
|
||||
TRY_RESULT(constructor_value, object.extract_required_field("@type", JsonValue::Type::Null));
|
||||
int32 constructor = 0;
|
||||
if (constructor_value.type() == JsonValue::Type::Number) {
|
||||
constructor = to_integer<int32>(constructor_value.get_number());
|
||||
|
@ -83,7 +83,7 @@ class GoogleDnsResolver final : public Actor {
|
||||
return Status::Error("Failed to parse DNS result: not an object");
|
||||
}
|
||||
auto &object = json_value.get_object();
|
||||
TRY_RESULT(answer, get_json_object_field(object, "Answer", JsonValue::Type::Array, false));
|
||||
TRY_RESULT(answer, object.extract_required_field("Answer", JsonValue::Type::Array));
|
||||
return get_ip_address(answer);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user