aboutsummaryrefslogtreecommitdiffstats
path: root/src/activitypub/appost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/activitypub/appost.cpp')
-rw-r--r--src/activitypub/appost.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/activitypub/appost.cpp b/src/activitypub/appost.cpp
new file mode 100644
index 0000000..dadefe8
--- /dev/null
+++ b/src/activitypub/appost.cpp
@@ -0,0 +1,71 @@
+#include "appost.h"
+
+APPost::APPost(APObjectFields fields) {
+ for (QString actor_url : fields.to_actors)
+ to_actors.push_back(APActor(actor_url));
+ for (QString actor_url : fields.cc_actors)
+ cc_actors.push_back(APActor(actor_url));
+ by_actor = fields.by_actor;
+
+ object_url = fields.object_url;
+ web_url = fields.web_url;
+ reply_to_url = fields.reply_to_url;
+ published = QDateTime::fromString(fields.published, Qt::ISODate);
+
+ for (APAttachmentFields attachment : fields.attachments)
+ attachments.push_back(APAttachment(attachment));
+
+ languages = fields.languages;
+ content = fields.content;
+
+ if (not fields.summary.isEmpty()) {
+ is_sensitive = true;
+ summary = fields.summary;
+ }
+
+ visibility = fields.visibility;
+}
+
+QString APPost::get_html_status_languages() {
+ QString text;
+
+ for (auto lang : languages)
+ text.append(lang + ", ");
+
+ if (text.isEmpty())
+ text = "<em>(unknown)</em>";
+ else
+ text.chop(2); // remove leftover ", "
+
+ return text;
+}
+
+QString APPost::get_html_render(HtmlRenderDetails render_info) {
+ QString html(get_html_template("appost"));
+
+ if (published.isValid()) {
+ // TODO: add a UI setting for configuring the display of local time or UTC time.
+ // Using QLocale::toString() is forward compatible with Qt 6 as QDateTime::toString() will not return anymore a string in the system locale.
+ html.replace("{{published}}", render_info.locale->toString(published.toLocalTime()));
+ }
+
+ html.replace("{{url-id}}", object_url);
+
+ html.replace("{{to}}", to_actors.get_html_render(render_info));
+ html.replace("{{cc}}", cc_actors.get_html_render(render_info));
+ html.replace("{{by}}", by_actor.get_html_render(render_info));
+
+ QString summary_text = summary;
+ if (summary_text.isEmpty())
+ summary_text = "<em>(empty)</em>";
+ html.replace("{{summary}}", summary_text);
+
+ html.replace("{{attachment-div}}", attachments.get_html_render(render_info));
+
+ html.replace("{{url-status}}", web_url);
+
+ html.replace("{{content}}", content);
+ html.replace("{{lang}}", get_html_status_languages());
+
+ return html;
+}