diff options
author | ConfuSomu | 2023-07-18 00:00:20 +0200 |
---|---|---|
committer | ConfuSomu | 2023-07-18 00:00:20 +0200 |
commit | 5ed7d9b53a65aec1f4793f62ac15195c44224b39 (patch) | |
tree | 20f59b643ab185abc8eeecb6338d565ed36febda /src/archive_parser.cpp | |
parent | e322946df7c33f76dbee46ec5b8e2118fbae8a26 (diff) | |
download | ActorViewer-5ed7d9b53a65aec1f4793f62ac15195c44224b39.tar ActorViewer-5ed7d9b53a65aec1f4793f62ac15195c44224b39.tar.gz ActorViewer-5ed7d9b53a65aec1f4793f62ac15195c44224b39.zip |
Implement Question object type support
This commit adds support for dealing with ActivityPub Questions, which
are polls. They are like Notes (posts) but contain a few more keys that
record information about the poll options, number of votes and poll
closure date.
Diffstat (limited to 'src/archive_parser.cpp')
-rw-r--r-- | src/archive_parser.cpp | 35 |
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}); |