aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive_parser.cpp')
-rw-r--r--src/archive_parser.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp
index fbc8aa0..25d1b76 100644
--- a/src/archive_parser.cpp
+++ b/src/archive_parser.cpp
@@ -42,10 +42,9 @@ std::variant<QString, Archive::InitError> Archive::init() {
return JsonNotObject;
// Do some more throughful checks to make sure that the JSON is actually valid and is a Mastodon data export (the only type supported currently)
- if (not (outbox_json->contains("@context") and outbox_json->value("@context").isString() and
- (outbox_json->value("@context").toString() == "https://www.w3.org/ns/activitystreams")))
+ if (not json_check_item(outbox_json->value("@context"), "https://www.w3.org/ns/activitystreams"))
return JsonNotActivityStream;
- if (outbox_json->contains("orderedItems") and outbox_json->value("orderedItems").isArray()) {
+ if (outbox_json->value("orderedItems").isArray()) {
outbox_items = new QJsonArray(outbox_json->value("orderedItems").toArray()); // we'll need it during Archive's lifetime
} else
return JsonParseError;
@@ -349,3 +348,16 @@ void Archive::find_attachment_dir(QString example_attachment) {
}
// If the attachment directory wasn't found, it will be searched for next attachment url parsing as attachment_dir_have_to_find wasn't touched (and is still true)
}
+
+bool Archive::json_check_item(const QJsonValue& value, const QString& item) {
+ // This allows us to avoid having an "and" condition that has QJsonObject::contains() and simplifies the if statement to only having this current function
+ if (value.type() == QJsonValue::Undefined) return false;
+
+ if (value.toString() == item)
+ return true;
+ else if (value.isArray()) {
+ QJsonArray array = value.toArray();
+ return array.contains(item);
+ } else
+ return false;
+}