Fix handling posts/fields with missing keys
https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c https://social.kernel.org/@monsieuricon/Ac8RXJRqxTfUrM1xQG
This commit is contained in:
parent
57202de5e8
commit
a21c1e22bc
10
models.cpp
10
models.cpp
|
@ -19,7 +19,9 @@ void from_json(const json& j, Emoji& emoji) {
|
||||||
void from_json(const json& j, AccountField& field) {
|
void from_json(const json& j, AccountField& field) {
|
||||||
j.at("name").get_to(field.name);
|
j.at("name").get_to(field.name);
|
||||||
field.value_html = j.at("value").get<std::string>();
|
field.value_html = j.at("value").get<std::string>();
|
||||||
if (j.at("verified_at").is_null()) {
|
// https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c
|
||||||
|
// https://social.kernel.org/@monsieuricon/Ac8RXJRqxTfUrM1xQG
|
||||||
|
if (!j.contains("verified_at") || j["verified_at"].is_null()) {
|
||||||
field.verified_at = -1;
|
field.verified_at = -1;
|
||||||
} else {
|
} else {
|
||||||
field.verified_at = parse_rfc3339(j["verified_at"].get_ref<const std::string&>());
|
field.verified_at = parse_rfc3339(j["verified_at"].get_ref<const std::string&>());
|
||||||
|
@ -104,7 +106,8 @@ void from_json(const json& j, Post& post) {
|
||||||
j.at("replies_count").get_to(post.replies_count);
|
j.at("replies_count").get_to(post.replies_count);
|
||||||
j.at("reblogs_count").get_to(post.reblogs_count);
|
j.at("reblogs_count").get_to(post.reblogs_count);
|
||||||
j.at("favourites_count").get_to(post.favorites_count);
|
j.at("favourites_count").get_to(post.favorites_count);
|
||||||
if (!j.at("edited_at").is_null()) {
|
// https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c
|
||||||
|
if (j.contains("edited_at") && !j["edited_at"].is_null()) {
|
||||||
post.edited_at = parse_rfc3339(j["edited_at"].get_ref<const std::string&>());
|
post.edited_at = parse_rfc3339(j["edited_at"].get_ref<const std::string&>());
|
||||||
} else {
|
} else {
|
||||||
post.edited_at = -1;
|
post.edited_at = -1;
|
||||||
|
@ -117,7 +120,8 @@ void from_json(const json& j, Post& post) {
|
||||||
j.at("account").get_to(post.account);
|
j.at("account").get_to(post.account);
|
||||||
j.at("media_attachments").get_to(post.media_attachments);
|
j.at("media_attachments").get_to(post.media_attachments);
|
||||||
j.at("emojis").get_to(post.emojis);
|
j.at("emojis").get_to(post.emojis);
|
||||||
if (!j.at("poll").is_null()) {
|
// https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c
|
||||||
|
if (j.contains("poll") && !j["poll"].is_null()) {
|
||||||
post.poll = j["poll"].get<Poll>();
|
post.poll = j["poll"].get<Poll>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue