aboutsummaryrefslogtreecommitdiffstats
path: root/src/activitypub/apquestion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/activitypub/apquestion.cpp')
-rw-r--r--src/activitypub/apquestion.cpp47
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;
+}