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.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp
index d9d4cf1..30e613a 100644
--- a/src/archive_parser.cpp
+++ b/src/archive_parser.cpp
@@ -5,6 +5,7 @@
#include <QFile>
#include <QJsonParseError>
#include <QTextDocument>
+#include <QFileInfo>
Archive::Archive(QString outbox_filename, ArchiveType archive_type) :
outbox_filename(outbox_filename), archive_type(archive_type) {}
@@ -166,6 +167,22 @@ QString* get_html_status_info_template() {
return html;
}
+QString* get_html_status_info_attachment_template() {
+ static QString* html = new QString();
+
+ if (html->isNull()) {
+ QFile file("src/templates/attachment.html");
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ html->append("<i>Error loading attachment template.</i>");
+ return html;
+ }
+
+ html->append(file.readAll());
+ }
+
+ return html;
+}
+
QString get_html_status_object_as_list(QJsonObject obj, QString element_name) {
QString text;
@@ -184,6 +201,36 @@ QString get_html_status_object_as_list(QJsonObject obj, QString element_name) {
return text;
}
+QString Archive::get_html_status_attachments(QJsonValueRef attachments_ref) {
+ QString text;
+ QJsonArray attachments = attachments_ref.toArray();
+
+ int i = 1;
+ for (auto attachment_ref : attachments) {
+ QString att_html(*get_html_status_info_attachment_template());
+ QJsonObject attachment = attachment_ref.toObject();
+
+ if (attachment.contains("mediaType") and attachment["mediaType"].toString().startsWith("image/")) {
+ att_html.replace("{{id}}", QString::number(i));
+
+ if (attachment.contains("url")) {
+ QString url = attachment["url"].toString();
+ QFileInfo path(outbox_filename);
+ url.prepend(path.absolutePath());
+ att_html.replace("{{path}}", url);
+ }
+
+ if (attachment.contains("name"))
+ att_html.replace("{{alt-text}}", attachment["name"].toString());
+
+ text.append(att_html);
+ }
+ ++i;
+ }
+
+ return text;
+}
+
// status_index is assumed to be a valid index
QString Archive::get_html_status_info(int status_index) {
QString info_text(*get_html_status_info_template());
@@ -211,6 +258,8 @@ QString Archive::get_html_status_info(int status_index) {
info_text.replace("{{summary}}", summary_text);
}
+ info_text.replace("{{attachment-div}}", get_html_status_attachments(activity["attachment"]));
+
if (activity.contains("url") and activity["url"].isString())
info_text.replace("{{url-status}}", activity["url"].toString());