aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConfuSomu2023-01-05 21:57:33 -0500
committerConfuSomu2023-01-05 21:57:33 -0500
commit8c202e0719bb417f8e495cd4761799c6a694a26f (patch)
treeacf2787b0d39fd9db596ed35ea5a2fd897465a0f
parenta962b2d93227557c68a719b2401f8d6bb3969899 (diff)
downloadActorViewer-8c202e0719bb417f8e495cd4761799c6a694a26f.tar
ActorViewer-8c202e0719bb417f8e495cd4761799c6a694a26f.tar.gz
ActorViewer-8c202e0719bb417f8e495cd4761799c6a694a26f.zip
Display image attachments in status info
-rw-r--r--src/archive_parser.cpp49
-rw-r--r--src/archive_parser.h2
-rw-r--r--src/templates/attachment.html4
-rw-r--r--src/templates/status_info.html1
4 files changed, 56 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());
diff --git a/src/archive_parser.h b/src/archive_parser.h
index 98fd2b8..0a1d5f3 100644
--- a/src/archive_parser.h
+++ b/src/archive_parser.h
@@ -37,4 +37,6 @@ private:
QJsonObject *outbox_json = nullptr;
QJsonArray *outbox_items = nullptr;
+
+ QString get_html_status_attachments(QJsonValueRef attachments_ref);
};
diff --git a/src/templates/attachment.html b/src/templates/attachment.html
new file mode 100644
index 0000000..4c7731c
--- /dev/null
+++ b/src/templates/attachment.html
@@ -0,0 +1,4 @@
+<h2>Attachment {{id}}</h2><br/>
+<img src="{{path}}" style="display:span;float:none;" width="440"/>
+<p style="text-indent:5px;"><b>Alt:</b> {{alt-text}}</p>
+<hr width="80%" />
diff --git a/src/templates/status_info.html b/src/templates/status_info.html
index a081463..a51c066 100644
--- a/src/templates/status_info.html
+++ b/src/templates/status_info.html
@@ -15,5 +15,6 @@
<div><tt id="content-warning"><b>CW:</b> {{summary}}</tt></div>
<div id="content">{{content}}</div>
+ <div id="attachments">{{attachment-div}}</div>
</body>
</html>