From c269400dbb2e40d60349ab0a1d67414303653c91 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Thu, 5 Jan 2023 02:54:59 -0500 Subject: Display status info when list item activated --- src/archive_parser.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/archive_parser.cpp') 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("Error loading status_info template."); + 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 = "(empty)"; + 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 = "(empty)"; + 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; +} -- cgit v1.2.3-54-g00ecf