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/activitypub/apquestion.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/activitypub/apquestion.cpp')
-rw-r--r-- | src/activitypub/apquestion.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/activitypub/apquestion.cpp b/src/activitypub/apquestion.cpp new file mode 100644 index 0000000..d519947 --- /dev/null +++ b/src/activitypub/apquestion.cpp @@ -0,0 +1,47 @@ +#include "apquestion.h" +#include <QDebug> + +APQuestion::APQuestion(APObjectFields fields) : APPost(fields) { + end_time = QDateTime::fromString(fields.question.end_time, Qt::ISODate); + closed_time = QDateTime::fromString(fields.question.closed_time, Qt::ISODate); + total_votes = fields.question.total_votes; + + for (APQuestionFields::Option elem : fields.question.poll_options) { + options.push_back({elem.name, elem.votes}); + } + + qDebug() << options.size(); +} + +QString APQuestion::get_html_render(HtmlRenderDetails render_info) { + QString html(APPost::get_html_render(render_info)); + html.append(get_html_template("appoll")); + + if (end_time.isValid()) { + // TODO: add a UI setting for configuring the display of local time or UTC time. + html.replace("{{end-time}}", render_info.locale->toString(end_time.toLocalTime())); + } + if (closed_time.isValid()) { + // TODO: add a UI setting for configuring the display of local time or UTC time. + html.replace("{{closed-time}}", render_info.locale->toString(closed_time.toLocalTime())); + } + + html.replace("{{total-votes}}", render_info.locale->toString(total_votes)); + html.replace("{{options}}", get_html_poll_options(render_info)); + + return html; +} + +QString APQuestion::get_html_poll_options(HtmlRenderDetails render_info) { + QString full; + + for (PollOption option : options) { + QString html(get_html_template("appoll_item")); + html.replace("{{name}}", option.name); + html.replace("{{votes}}", render_info.locale->toString(option.votes)); + html.replace("{{votes-percent}}", render_info.locale->toString((int)((float)option.votes/(float)total_votes * 100))); + full.append(html); + } + + return full; +} |