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.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp
index 603ffa7..d3b9197 100644
--- a/src/archive_parser.cpp
+++ b/src/archive_parser.cpp
@@ -142,3 +142,75 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par
++i;
}
}
+
+QString* get_html_status_info_template() {
+ static QString* html = new QString();
+
+ if (html->isNull()) {
+ QFile file("src/templates/status_info.html");
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ html->append("<i>Error loading status_info template.</i>");
+ return html;
+ }
+
+ html->append(file.readAll());
+ }
+
+ return html;
+}
+
+QString get_html_status_object_as_list(QJsonObject obj, QString element_name) {
+ QString text;
+
+ if (obj.contains(element_name)) {
+ QJsonArray to = obj.value(element_name).toArray();
+
+ for (auto collection : to)
+ text.append(collection.toString() + ", ");
+ }
+
+ if (text.isEmpty())
+ text = "<em>(empty)</em>";
+ else
+ text.chop(2); // remove leftover ", "
+
+ 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());
+ QJsonObject obj = outbox_items->at(status_index).toObject();
+
+ if (obj.contains("type") and obj["type"].isString())
+ info_text.replace("{{type}}", obj["type"].toString());
+
+ if (obj.contains("published") and obj["published"].isString())
+ info_text.replace("{{published}}", obj["published"].toString());
+
+ if (obj.contains("id") and obj["id"].isString())
+ info_text.replace("{{url-id}}", obj["id"].toString());
+
+ info_text.replace("{{to}}", get_html_status_object_as_list(obj, "to"));
+ info_text.replace("{{cc}}", get_html_status_object_as_list(obj, "cc"));
+
+ if (obj["object"].isObject()) {
+ QJsonObject activity = obj["object"].toObject();
+
+ if (activity.contains("summary")) {
+ QString summary_text = activity["summary"].toString();
+ if (summary_text.isEmpty())
+ summary_text = "<em>(empty)</em>";
+ info_text.replace("{{summary}}", summary_text);
+ }
+
+ if (activity.contains("url") and activity["url"].isString())
+ info_text.replace("{{url-status}}", activity["url"].toString());
+
+ if (activity["content"].isString()) {
+ info_text.replace("{{content}}", activity["content"].toString());
+ }
+ }
+
+ return info_text;
+}