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.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp
index 25d1b76..8b2289e 100644
--- a/src/archive_parser.cpp
+++ b/src/archive_parser.cpp
@@ -6,6 +6,8 @@
#include "activitypub/apobject.h"
#include "activitypub/apreblog.h"
#include "activitypub/appost.h"
+#include "activitypub/apquestion.h"
+#include "activitypub/fields.h"
#include <QFile>
#include <QJsonParseError>
@@ -245,6 +247,7 @@ const QString Archive::get_html_status_info(int status_index, int text_zone_widt
// The post
APObjectFields obj_fields;
+ APObjectType obj_type = APObjectType::UNKNOWN;
if (activity.contains("type") and activity["type"].isString()) {
QString type = activity["type"].toString();
@@ -269,6 +272,14 @@ const QString Archive::get_html_status_info(int status_index, int text_zone_widt
// the JSON AP Object
QJsonObject object = activity["object"].toObject();
+ {
+ QString type = object["type"].toString();
+ if (type == "Note")
+ obj_type = APObjectType::NOTE;
+ else if (type == "Question")
+ obj_type = APObjectType::QUESTION;
+ }
+
obj_fields.visibility = get_status_type(object);
if (object.contains("summary"))
@@ -290,13 +301,31 @@ const QString Archive::get_html_status_info(int status_index, int text_zone_widt
obj_fields.by_actor = object["attributedTo"].toString();
obj_fields.published = object["published"].toString();
+ if (obj_type == APObjectType::QUESTION) {
+ obj_fields.question = {
+ .end_time = object["endTime"].toString(),
+ .closed_time = object["closed"].toString(),
+ .total_votes = object["votersCount"].toInt()
+ };
+ for (QJsonValue elem : object["oneOf"].toArray())
+ obj_fields.question.poll_options.push_back({
+ (elem["type"].toString() == "Note") ? elem["name"].toString() : "?",
+ elem["replies"].toObject()["totalItems"].toInt()
+ });
+ }
+
} else if (activity["object"].isString())
obj_url = activity["object"].toString();
- if (obj_url.isNull())
- act_fields.object = new APPost(obj_fields);
- else
+ if (not obj_url.isNull())
act_fields.object = new APReblog({obj_url, act_fields.visibility});
+ else switch(obj_type) {
+ case APObjectType::UNKNOWN:
+ case APObjectType::NOTE:
+ act_fields.object = new APPost(obj_fields); break;
+ case APObjectType::QUESTION:
+ act_fields.object = new APQuestion(obj_fields); break;
+ }
// TODO: it is currently a waste to create this APActivity object that will be immediately destroyed but it allows us to extend archive parsing to something that will become abstract (and an abstract base class) and separate from display (the final goal) which will allow us to add other sources that feed us with posts, reblogs and Actor information. furthermore, these objects can be cached for reuse in a session.
return APActivity(act_fields).get_html_render({text_zone_width, locale});