The inbox with drawn signs: a letter, the doctor's case, a coin, a newspaper

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 19:58:07 +01:00
1 parent f4d44364c7
commit 9d94d05db1
2 files changed
+26 -26

No files matched your search

+25 -26
View File
@@ -1,34 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-only
namespace {std::string news_body_markup(const std::string &text){auto value=esc(text);size_t at=0;while((at=value.find('\n',at))!=std::string::npos){value.replace(at,1,"<br/>");at+=5;}return value;}}
// The picture of a message: the crest of the club it is about, the flag for the national side,
// else one of four drawn signs: a letter, the doctor's case, a coin, a newspaper.
std::string App::render_news_art(const Json &message, double size) {
const auto kind = message.at("kind").get<std::string>();
const auto sign = [&](const char *name, const std::string &body) {
return picture(renderer_.diagram(std::string("news-sign-") + name, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 48 48\">" + body + "</svg>", 192), size * .95, size * .95);
};
const auto has = [&](std::initializer_list<const char *> words) {
const auto text = message.value("title", std::string()) + " " + message.value("body", std::string());
return std::any_of(words.begin(), words.end(), [&](const char *word) { return text.find(word) != std::string::npos; });
};
static const std::string letter = "<path d=\"M6 12h36v24H6z\" fill=\"#fbf7ee\" stroke=\"#3a332b\" stroke-width=\"2\"/><path d=\"M6 12l18 14 18-14\" fill=\"none\" stroke=\"#3a332b\" stroke-width=\"2\"/>";
static const std::string doctor = "<rect x=\"8\" y=\"12\" width=\"32\" height=\"26\" rx=\"5\" fill=\"#fbf7ee\" stroke=\"#3a332b\" stroke-width=\"2\"/><path d=\"M24 17v16M16 25h16\" stroke=\"#c8402f\" stroke-width=\"5\"/>";
static const std::string coin = "<circle cx=\"24\" cy=\"24\" r=\"16\" fill=\"#f1cf7a\" stroke=\"#a8782e\" stroke-width=\"2.5\"/><path d=\"M30.5 18.5a8 8 0 1 0 0 11M15.5 22h10M15.5 26h10\" fill=\"none\" stroke=\"#6b4a12\" stroke-width=\"2.6\" stroke-linecap=\"round\"/>";
static const std::string paper = "<rect x=\"7\" y=\"9\" width=\"34\" height=\"30\" rx=\"2\" fill=\"#fbf7ee\" stroke=\"#3a332b\" stroke-width=\"2\"/><path d=\"M12 16h24M12 22h10M12 27h10M12 32h10\" stroke=\"#3a332b\" stroke-width=\"2\"/><rect x=\"26\" y=\"21\" width=\"10\" height=\"12\" fill=\"#c0b6a5\"/>";
std::string art;
if(kind=="mail")art=glyph("mail",size*.65);
else if (kind == "national" ||
(message.contains("scope") &&
message.at("scope").value("kind", "") == "national"))
art = picture(
renderer_.diagram("news-national-flag", ui_nation_flag_svg("de"), 176),
size * .69, size * .46);
else if (kind == "club" || kind == "career") {
const auto id =
message.value("scope", Json::object()).value("id", std::string());
art = crest(world_->find("clubs", id), size * .69);
if (art.empty())
art = glyph("world", size * .55);
} else {
const auto key =
kind == "fixture" ? "button.league"
: kind == "transfer" ? "button.contracts"
: kind == "finance"
? (gui_.contains("news.cash") ? "news.cash" : "icon.coins")
: kind == "training" ? "button.training"
: "button.stadium";
art = img(key, size * .76, size * .76, false, false, 256);
if (kind == "national" || (message.contains("scope") && message.at("scope").value("kind", "") == "national"))
art = picture(renderer_.diagram("news-national-flag", ui_nation_flag_svg("de"), 176), size * .69, size * .46);
else if (kind == "club" || kind == "career")
art = crest(world_->find("clubs", message.value("scope", Json::object()).value("id", std::string())), size * .69);
if (art.empty()) {
// what a letter is about decides its sign: an injury, money, a report of a match
if (has({"verletz", "Verletz", "fällt", "Arzt", "Prellung", "prellung", "Zerrung", "riss"})) art = sign("doctor", doctor);
else if (kind == "finance" || has({"€", "Prämie", "prämie", "Werbe", "Sponsor", "Zinsen", "Kredit"})) art = sign("coin", coin);
else if (kind == "fixture" || message.value("category", std::string()) == "Bericht") art = sign("paper", paper);
else art = sign("letter", letter);
}
return "<div class=\"news-art news-art-" + esc(kind) +
"\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) +
"dp;\">" + art + "</div>";
return "<div class=\"news-art news-art-" + esc(kind) + "\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) + "dp;\">" + art + "</div>";
}
// The messages of a folder as rows of the page: a dot while unread, the sender's picture, date
// and kind, the headline as a link, a line of the text, and the two things one does with a
@@ -44,7 +43,7 @@ std::string App::render_news_feed(const Json &data) {
const auto id = m.at("id").get<std::string>(), name = m.at("title").get<std::string>();
const bool unread = m.at("read").is_boolean() && !m.at("read").get<bool>(), archived = m.at("folder") == "archive" || (engine_mode_ && m.at("folder") == "trash");
const auto category = m.at("category").get<std::string>();
out += "<div id=\"news-row-" + id + "\" class=\"nw-row" + std::string(unread ? " is-unread" : "") + "\"><span class=\"nw-dot\"></span><span class=\"nw-art\">" + render_news_art(m, 86) + "</span><div class=\"nw-copy\"><div class=\"pg-row pg-mut\" style=\"" +
out += "<div id=\"news-row-" + id + "\" class=\"nw-row" + std::string(unread ? " is-unread" : "") + "\"><span class=\"nw-dot\"></span><span class=\"nw-art\">" + render_news_art(m, 100) + "</span><div class=\"nw-copy\"><div class=\"pg-row pg-mut\" style=\"" +
pg_css("gap:8px;font-size:12px;") + "\"><span>" + esc(m.at("display_date").get<std::string>()) + "</span><span class=\"pg-tag" + std::string(category == "Bericht" ? " sage" : "") + "\">" + esc(category) + "</span>" +
(unread ? "<span class=\"pg-tag accent\">Neu</span>" : "") + (data.value("fictional", false) ? "<span class=\"pg-tag\">Demo</span>" : "") + "</div>" +
btn("news-open", "<span>" + esc(name) + "</span>", "pg-link nw-title", "id=\"news-read-" + id + "\" data-id=\"" + id + "\" aria-label=\"Nachricht lesen: " + esc(name) + "\"") +