diff options
author | ConfuSomu | 2023-07-05 15:14:46 +0200 |
---|---|---|
committer | ConfuSomu | 2023-07-05 15:14:46 +0200 |
commit | e515ca109faa897e84be8a97a1240c59df612dd4 (patch) | |
tree | 2a5e0593bb4387449a9a60fb2aefcc74779b5c67 /src/activitypub/appost.cpp | |
parent | 0dfab2456b2dcd33f1879ac7d5606dd65cdb8e40 (diff) | |
download | ActorViewer-e515ca109faa897e84be8a97a1240c59df612dd4.tar ActorViewer-e515ca109faa897e84be8a97a1240c59df612dd4.tar.gz ActorViewer-e515ca109faa897e84be8a97a1240c59df612dd4.zip |
Implement a small library of ActivityPub objects
These objects allow, and will allow us, to move HTML rendering out of
the archive parser and into separate classes. Each of the derived
classes specialise HTML rendering for their specific requirements.
Furthermore, these ActivityPub objects will be able to be expanded upon
and have support to be written to disk, in a database, for instance.
Separating ActivityPub object retrieving from rendering allows us to
implement other retrieving sources and methods, such as downloading
posts from a configured remote instance.
Diffstat (limited to 'src/activitypub/appost.cpp')
-rw-r--r-- | src/activitypub/appost.cpp | 71 |
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; +} |