#include "appost.h"
#include "src/settings_interface.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 = "(unknown)";
else
text.chop(2); // remove leftover ", "
return text;
}
QString APPost::get_html_render(HtmlRenderDetails render_info) {
QString html(get_html_template(QStringLiteral("appost")));
if (published.isValid()) {
// 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(
SettingsInterface::quick_read_setting("ui/timezone") ? published.toUTC() : 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 = "(empty)";
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;
}