Modern UI contract: mailbox messages and news.update
The news read carries the desk manager's mailbox as the contract's messages with ids that survive the original's compaction. news.update marks a message read or unread, moves it to the trash and back (saved marks; the message stays in the original mailbox) and archives it as the original's keep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c361dccd34
commit
179cd970ad
6 files changed
+139
-2
No files matched your search
@@ -35,7 +35,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
|
||||
| `advertising` | 14 Banden (`ad:board/<n>`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad-<Platz>-<Nr.>`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals |
|
||||
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` und `maxStage`: Classic 3, Modern-Welt 4; sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
|
||||
| `transfer` | die Transferliste (`listing:<n>`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Monat, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen; `details` je Spieler mit vollständigem Namen, Nationalität, Foto, Kondition/Technik/Form und sieben Fähigkeiten; `activeStrengths`/`teamStrengths` enthalten vier Positionen und Gesamtschnitt. `ownBid.monthlySalary` ist das gespeicherte Monatsgehalt; `annualSalary` bleibt als früher irreführend benannter Alias erhalten. `salaryReferencePeriod: month`. `loanAvailable` sperrt vereinslose Anbieter; `offerTerms` liefert Kauf-/Leihgebühr, jeweilige maximale Gebühr und maximales Monatsgehalt aus den Original-Editorgrenzen. `ownBid.loan` bezeichnet die gespeicherte Leihart. `ownBid.bonuses` sind sieben gespeicherte Prämienstufen. Die Projektion und Gebotsprüfung verwenden den weltabhängigen Modern-Pool, nicht Classic `0xb70` (#24). |
|
||||
| `news` | Presseereignisse eines Teams (`teamId`, Vorgabe das Team am Schreibtisch), `from`/`until` (ISO, Vorgabe bis heute), `limit` (Vorgabe 50, die neuesten): `events` je `{id, type, date, scope, data, variant: null}` nach [Pressevertrag](../new_ui/integration/PRESS.md), `total`. Quelle ist der Almanach, darum gleich bei jedem Lesen und mit stabiler ID (`press-event:<Typ>:<Vorkommnis>:<Team>`). Typen: `match.result`, `cup.round_result`, `cup.final_result`, `cup.extra_time`, `cup.penalties`, `player.sent_off`, `player.injury`, `run.wins` (3/5/8/10/15), `run.unbeaten` (5/10/15/20/30), `run.winless` (5/8/10/15), `run.losses` (3/5/8/10), `league.position`, `league.champion`, `cup.won`, `indoor.won`. Fakten: `team`, `opponent`, `competition` (mit `kind`, `season`), `matchId`, `score {for, against}` aus Sicht des Teams, `venue`, `trailed`, `minute` (das entscheidende Tor), `outcome`, `round`, `shootout`, `player`, `matches`, `position`, `points`. Dazu Geschäftsereignisse aus dem Pressejournal im Spielstand (`state/modern.json`, `press`): beim Anstoß aus dem Kadervergleich der menschlichen Vereine `transfer.signed` (`fromClub`), `transfer.free`, `transfer.sold` (`toClub`; auch ein freigegebener Spieler, der im selben Anstoß woanders unterschreibt), `contract.ended`; `toto.win`/`toto.loss` (`amount`); `career.season_finished`/`career.season_started`; beim Saisonwechsel `league.promoted`/`league.relegated` (`competition` die neue, `from` die alte Liga); aus bestätigten Befehlen `contract.extended` (`years`, `wage`), `advertising.signed` (`company`, `amount` monatlich, `months`, `place` boards/shirt/tv), `finance.loan_approved`/`finance.loan_repaid` (`amount`, `bank`), `stadium.expansion_planned` (`block`, `seats` Ziel insgesamt) und `career.manager_resigned`. Ablösen kennt der Kadervergleich nicht (`fee: null`). Ohne Welt-IDs (Classic-Daten) heißt ein Verein `team:<Laufzeitnummer>`, die sich zum Saisonstart ändern kann. Monatlich `finance.profit`/`finance.loss` (`amount` die Veränderung des Kontostands im abgelaufenen Monat, alles Gebuchte eingeschlossen, `month` als JJJJ-MM; vermerkt beim ersten Anstoß im neuen Monat). Beim Anstoß `stadium.expansion_finished` (`count` die Plätze des Stadions danach), wenn die Bauzeit eines Tribünenblocks abläuft. Noch nicht: Derby, Aktien |
|
||||
| `news` | Presseereignisse eines Teams (`teamId`, Vorgabe das Team am Schreibtisch), `from`/`until` (ISO, Vorgabe bis heute), `limit` (Vorgabe 50, die neuesten): `events` je `{id, type, date, scope, data, variant: null}` nach [Pressevertrag](../new_ui/integration/PRESS.md), `total`. Quelle ist der Almanach, darum gleich bei jedem Lesen und mit stabiler ID (`press-event:<Typ>:<Vorkommnis>:<Team>`). Typen: `match.result`, `cup.round_result`, `cup.final_result`, `cup.extra_time`, `cup.penalties`, `player.sent_off`, `player.injury`, `run.wins` (3/5/8/10/15), `run.unbeaten` (5/10/15/20/30), `run.winless` (5/8/10/15), `run.losses` (3/5/8/10), `league.position`, `league.champion`, `cup.won`, `indoor.won`. Fakten: `team`, `opponent`, `competition` (mit `kind`, `season`), `matchId`, `score {for, against}` aus Sicht des Teams, `venue`, `trailed`, `minute` (das entscheidende Tor), `outcome`, `round`, `shootout`, `player`, `matches`, `position`, `points`. Dazu Geschäftsereignisse aus dem Pressejournal im Spielstand (`state/modern.json`, `press`): beim Anstoß aus dem Kadervergleich der menschlichen Vereine `transfer.signed` (`fromClub`), `transfer.free`, `transfer.sold` (`toClub`; auch ein freigegebener Spieler, der im selben Anstoß woanders unterschreibt), `contract.ended`; `toto.win`/`toto.loss` (`amount`); `career.season_finished`/`career.season_started`; beim Saisonwechsel `league.promoted`/`league.relegated` (`competition` die neue, `from` die alte Liga); aus bestätigten Befehlen `contract.extended` (`years`, `wage`), `advertising.signed` (`company`, `amount` monatlich, `months`, `place` boards/shirt/tv), `finance.loan_approved`/`finance.loan_repaid` (`amount`, `bank`), `stadium.expansion_planned` (`block`, `seats` Ziel insgesamt) und `career.manager_resigned`. Ablösen kennt der Kadervergleich nicht (`fee: null`). Ohne Welt-IDs (Classic-Daten) heißt ein Verein `team:<Laufzeitnummer>`, die sich zum Saisonstart ändern kann. Monatlich `finance.profit`/`finance.loss` (`amount` die Veränderung des Kontostands im abgelaufenen Monat, alles Gebuchte eingeschlossen, `month` als JJJJ-MM; vermerkt beim ersten Anstoß im neuen Monat). Beim Anstoß `stadium.expansion_finished` (`count` die Plätze des Stadions danach), wenn die Bauzeit eines Tribünenblocks abläuft. Noch nicht: Derby, Aktien. Dazu `messages`: das Postfach des Managers am Schreibtisch (die Nachrichten des Originals; `id` stabil `message:<Tag>-<Texthash>`, auch wenn das Original seine Einträge zusammenschiebt; `subject` die erste Zeile, `paragraphs` der Text, `read`, `folder` inbox/archive/trash); `articles` leer (die UI rendert und hält ihre Artikel), `dedupePolicyId` |
|
||||
| `calendar` | der Saisonkalender des Teams am Schreibtisch, `from`/`until` (ISO, Vorgabe der laufende Monat): `days` (Datum, `seasonDay`, `today`, `eventKinds`: `league`, `cup:<n>`, `replay`, `indoor`, `special`, `national`, `friendly`; `fixtureIds`) und `fixtures` (die eigenen Ligaspiele: `fixture:league-<Liga>-<Runde>-<Nr.>`, Wettbewerb, Runde, `originalDate`, `scheduledDate`, Heim/Gast, `status` `scheduled`/`played`/`rescheduled`/`postponed`, `result`). Verlegte und im Winter ausgefallene Spiele stehen am Nachholtag. Pokalspiele nur als `eventKinds`; Fehler `invalid_range` |
|
||||
| `scheduling` | die verlegbaren eigenen Ligaspiele (`move:<Tag>-<Liga>-<Runde>-<Nr.>`, Datum, Runde, Heim/Gast, mögliche Zieldaten) und die verlegten, die sich zurücknehmen lassen |
|
||||
| `friendly` | mit `opponentId`, optional `home`: das Angebot für ein Freundschaftsspiel (Heim/Gast, Kosten, Zahler, ob der Gegner einen menschlichen Manager hat) und die freien Daten der Saison; kein Zufall. Am Schreibtisch des Bundestrainers ein Länderspiel (`national: true`, Gegner ein anderes Nationalteam, dazu `ratings` beider Teams): das Original zieht für die Bewertung Zufall; der Read rechnet auf einer Kopie des Generators, die Buchung zieht dieselben Zahlen |
|
||||
@@ -99,6 +99,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
|
||||
| `live.tactics` | `values` (8) | Taktik wie im Taktik-Bildschirm während des Spiels; Fehler `invalid_tactic` |
|
||||
| `live.finish` | `{}` | spielt den Spieltag ohne weiteren Halt zu Ende; Antwort wie `session.advance` (bei fehlender Vertragsentscheidung wird der ganze Live-Spieltag zurückgerollt: `decision_pending`) |
|
||||
| `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:<n>`, `fund:<n>`) und `count` oder `credit` mit `lenderId` (optional), `edits` wie im Read `credit` und `acceptFees` (Gebühren wie im Original bestätigen) | wie die Bank am Schreibtisch; Fehler `invalid_amount`, `amount_unavailable`, `invalid_share_count`, `insufficient_funds`, `investment_limit`, `invalid_fund_count` u. a. |
|
||||
| `news.update` | `messageId`, `action` `read`/`unread`/`archive`/`trash`/`restore` | eine Nachricht des eigenen Postfachs: gelesen und Papierkorb sind Markierungen der Oberfläche (im Spielstand, `news_marks` je Manager; die Nachricht bleibt im Postfach des Originals, `restore` holt sie zurück), `archive` ist das „Behalten“ des Originals (eine behaltene Nachricht wird bei vollem Postfach nicht verdrängt), `restore` gibt sie wieder frei. Endgültiges Löschen bietet die Schnittstelle nicht an. Unverändert: `no_change`; Fehler `unknown_message` |
|
||||
| `lineup.commit` | `order`: Spieler-IDs in der gewünschten Reihenfolge | öffnet die Aufstellung wie am Schreibtisch und tauscht die Zeilen; Fehler `unknown_player`, `lineup_refused` (z. B. Verletzte, Ausländerregel) |
|
||||
| `tactics.commit` | `values`: die acht Werte | jede geänderte Einstellung über die Prüfung der Taktiktafel (eine gesetzte Grundausrichtung beendet die Steuerung durch den Assistenten); Fehler `invalid_tactic` |
|
||||
| `training.commit` | optional `types` (4), `areas` (9), `players [{playerId, intensity}]` | richtet das Training bei Bedarf ein, setzt erst die Senkungen, dann die Erhöhungen (jeder Zwischenstand bleibt in den Grenzen); Fehler `training_unavailable`, `unknown_player` und die Gründe der Engine |
|
||||
|
||||
@@ -8763,6 +8763,26 @@ std::string ui_text(const cli::Json& j, const char* key) {
|
||||
return v && v->string() ? *v->string() : std::string{};
|
||||
}
|
||||
|
||||
// The original mailbox of a manager, each message with an id that stays the same while the
|
||||
// mailbox shifts its entries (the entry index does not): "message:<day>-<text hash>", "-<n>"
|
||||
// for the n-th equal message of a day.
|
||||
std::vector<std::pair<std::string, ui::MailboxMessage>> ui_mailbox(const ModernState& g, int manager) {
|
||||
std::vector<std::pair<std::string, ui::MailboxMessage>> out;
|
||||
ui::MailboxState box;
|
||||
try { box = ui::mailbox_state_from_game(g, manager); } catch (const std::exception&) { return out; }
|
||||
std::map<std::string, int> seen;
|
||||
for (auto& m : box.messages) {
|
||||
uint32_t hash = 2166136261u; // FNV-1a
|
||||
for (unsigned char c : m.text) hash = (hash ^ c) * 16777619u;
|
||||
char key[40];
|
||||
std::snprintf(key, sizeof key, "message:%u-%08x", unsigned(m.date_counter), hash);
|
||||
std::string id = key;
|
||||
if (const int n = seen[id]++; n > 0) id += "-" + std::to_string(n + 1);
|
||||
out.emplace_back(std::move(id), std::move(m));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// The runtime team a contract team id names (a world id or "team:<n>"), or -1.
|
||||
int ui_team_index(const ModernState& g, const std::string& id) {
|
||||
if (id.empty()) return -1;
|
||||
@@ -8950,6 +8970,34 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
context.career_ended = career_complete();
|
||||
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
|
||||
const int manager = context.manager;
|
||||
if (kind == "news" && manager >= 0 && size_t(manager) < g_.manager_teams.size()) {
|
||||
// the press events (content read) and the desk manager's mailbox: the original's messages
|
||||
// with the interface's read / folder marks (news.update; archive is the original's "keep")
|
||||
cli::Json answer = modern::ui_read(g_, context, request);
|
||||
auto* data = std::get_if<O>(&answer.value);
|
||||
if (!data || !data->count("data")) return answer;
|
||||
auto& d = std::get<O>((*data)["data"].value);
|
||||
const std::string owner = modern::ui_manager_id(g_, manager);
|
||||
const auto marks = g_.news_marks.find(owner);
|
||||
A messages;
|
||||
for (const auto& [id, m] : ui_mailbox(g_, manager)) {
|
||||
const uint8_t flags = marks == g_.news_marks.end() || !marks->second.count(id) ? 0 : marks->second.at(id);
|
||||
const AlmanacDate day = almanac_date(m.date_counter, g_.display_start_year);
|
||||
char date[16];
|
||||
std::snprintf(date, sizeof date, "%04d-%02d-%02d", day.year, day.month, day.day);
|
||||
const std::string first_line = m.text.substr(0, std::min(m.text.find('\n'), size_t(80)));
|
||||
const auto text = [](const std::string& t) { return cli::Json(O{{"key", nullptr}, {"text", t}, {"locale", "de"}, {"args", O{}}}); };
|
||||
messages.push_back(O{{"id", id}, {"ownerManagerId", owner}, {"date", date}, {"sender", text("Postfach")},
|
||||
{"subject", text(first_line)}, {"paragraphs", A{text(m.text)}}, {"category", "mail"},
|
||||
{"read", (flags & 1) != 0},
|
||||
{"folder", (flags & 2) ? "trash" : m.kept_for_manager ? "archive" : "inbox"},
|
||||
{"entityIds", A{}}, {"actionIds", A{}}});
|
||||
}
|
||||
d["messages"] = std::move(messages);
|
||||
d["articles"] = A{}; // the interface renders and keeps its articles (PRESS.md)
|
||||
d["dedupePolicyId"] = "rules:press-dedupe-v1";
|
||||
return answer;
|
||||
}
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "statistics" && kind != "opening" && kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit" &&
|
||||
@@ -10582,6 +10630,42 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
}
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"bank", "desktop"}, "Bankauftrag ausgeführt.");
|
||||
} else if (kind == "news.update") {
|
||||
// payload {messageId, action: read | unread | archive | trash | restore}: the desk manager's
|
||||
// mailbox. read/unread and the trash are the interface's marks (saved, the message stays
|
||||
// in the original mailbox, a restore brings it back); archive is the original's "keep"
|
||||
// (a kept message is not dropped when the mailbox is full), restore releases it again.
|
||||
const std::string id = ui_text(*payload, "messageId"), action = ui_text(*payload, "action");
|
||||
if (action != "read" && action != "unread" && action != "archive" && action != "trash" && action != "restore")
|
||||
return refuse("invalid_payload", "action ist read, unread, archive, trash oder restore.");
|
||||
const auto box = ui_mailbox(g_, manager);
|
||||
const auto it = std::find_if(box.begin(), box.end(), [&](const auto& m) { return m.first == id; });
|
||||
if (it == box.end()) return refuse("unknown_message", "Diese Nachricht gibt es nicht (mehr).");
|
||||
uint8_t& flags = g_.news_marks[modern::ui_manager_id(g_, manager)][id];
|
||||
const uint8_t before = flags;
|
||||
const bool kept = it->second.kept_for_manager;
|
||||
bool keep_toggle = false;
|
||||
if (action == "read") flags |= 1;
|
||||
else if (action == "unread") flags &= uint8_t(~1);
|
||||
else if (action == "trash") flags |= 2;
|
||||
else if (action == "archive") flags &= uint8_t(~2), keep_toggle = !kept;
|
||||
else flags &= uint8_t(~2), keep_toggle = kept; // restore: back to the inbox
|
||||
if (keep_toggle) {
|
||||
ui::MailboxActionRequest r;
|
||||
r.kind = ui::MailboxActionKind::toggle_keep;
|
||||
r.manager_slot = manager, r.revision = revision;
|
||||
r.entry_index = it->second.entry_index, r.expected_entry = it->second.raw_entry;
|
||||
uint64_t scratch = revision;
|
||||
if (!dispatch_mailbox(r, scratch, error)) { restore(); return refuse("mailbox_refused", error); }
|
||||
}
|
||||
if (flags == 0) g_.news_marks[modern::ui_manager_id(g_, manager)].erase(id);
|
||||
if (flags == before && !keep_toggle) {
|
||||
answer = modern::ui_command_result(request_id, previous, previous, {}, "Unverändert.");
|
||||
std::get<cli::Json::Object>(answer.value)["outcome"] = "no_change";
|
||||
} else {
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"news"}, "Postfach aktualisiert.");
|
||||
}
|
||||
} else if (kind == "lineup.commit") {
|
||||
// payload {order: [player ids]}: the squad in this order (the first eleven start); the
|
||||
// board opens as on the desk (the human line-up path), then rows are swapped into place
|
||||
|
||||
@@ -154,7 +154,7 @@ A allowed_commands(const ModernState& g, const UiContext& c) {
|
||||
"session.advance", "lineup.commit", "tactics.commit", "friendly.book", "manager.resign.commit",
|
||||
"training.commit", "camp.book", "bank.commit", "toto.submit", "quote.request", "contract.offer",
|
||||
"stadium.commit", "advertising.accept", "budget.commit", "ticket.commit", "transfer.submit",
|
||||
"sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel"};
|
||||
"sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel", "news.update"};
|
||||
A out;
|
||||
for (size_t i = 0; i < std::size(kAll); ++i)
|
||||
if (!national || i < 5) out.push_back(kAll[i]);
|
||||
|
||||
@@ -174,6 +174,15 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
|
||||
{"traffic_scale", int64_t(state.traffic_scale)},
|
||||
{"press", press_json(state.press)},
|
||||
{"press_serial", int64_t(state.press_serial)},
|
||||
{"news_marks", [&] {
|
||||
O managers;
|
||||
for (const auto& [manager, marks] : state.news_marks) {
|
||||
O m;
|
||||
for (const auto& [message, flags] : marks) m[message] = int(flags);
|
||||
managers[manager] = std::move(m);
|
||||
}
|
||||
return J(std::move(managers));
|
||||
}()},
|
||||
{"press_month", int64_t(state.press_month)},
|
||||
{"press_month_cash", [&] { A a; for (int64_t v : state.press_month_cash) a.push_back(v); return J(std::move(a)); }()},
|
||||
{"career_end_reason", state.career_end_reason},
|
||||
@@ -239,6 +248,10 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
|
||||
out.state.press = press_json(get(modern, "press"));
|
||||
out.state.press_serial = uint32_t(num(get(modern, "press_serial")));
|
||||
}
|
||||
if (const auto it = o->find("news_marks"); it != o->end() && it->second.object())
|
||||
for (const auto& [manager, marks] : *it->second.object())
|
||||
if (marks.object())
|
||||
for (const auto& [message, flags] : *marks.object()) out.state.news_marks[manager][message] = uint8_t(num(flags));
|
||||
if (o->count("press_month")) {
|
||||
out.state.press_month = uint32_t(num(get(modern, "press_month")));
|
||||
for (const J& v : arr(get(modern, "press_month_cash"))) out.state.press_month_cash.push_back(int64_t(num(v)));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -116,6 +117,9 @@ struct ModernState : GameState {
|
||||
// each manager's cash at its start; the change over a month is finance.profit / finance.loss.
|
||||
uint32_t press_month = 0;
|
||||
std::vector<int64_t> press_month_cash;
|
||||
// The interface's mailbox marks per manager id and message id (news.update): bit 0 read,
|
||||
// bit 1 in the trash. Keeping a message is the original's own flag in the mailbox.
|
||||
std::map<std::string, std::map<std::string, uint8_t>> news_marks;
|
||||
// How and when the career ended ("" while it runs; "career_completed" when the set duration ran
|
||||
// out, "last_human_resigned" when the only or last human manager gave up): the interface's
|
||||
// terminationReason and the end of the employments.
|
||||
|
||||
@@ -818,6 +818,41 @@ int main(int argc, char** argv) {
|
||||
check(jobs && !jobs->empty() && at((*jobs)[0], "teamId").string(), "employments of the manager");
|
||||
check(allowed && advance, "allowed commands of the desk");
|
||||
}
|
||||
// the mailbox: read, archive (the original's keep), trash and restore one message
|
||||
{
|
||||
const J box = session.ui_read(O{{"kind", "news"}}, rev);
|
||||
const auto* messages = at(at(box, "data"), "messages").array();
|
||||
std::printf("(mailbox: %zu messages)\n", messages ? messages->size() : 0);
|
||||
check(messages != nullptr, "news with the mailbox");
|
||||
if (messages && !messages->empty()) {
|
||||
const std::string id = s(at(messages->front(), "id"));
|
||||
const auto folder_of = [&]() {
|
||||
const J now = session.ui_read(O{{"kind", "news"}}, rev);
|
||||
if (const auto* list = at(at(now, "data"), "messages").array())
|
||||
for (const auto& m : *list)
|
||||
if (s(at(m, "id")) == id) return s(at(m, "folder")) + (truth(at(m, "read")) ? "+read" : "");
|
||||
return std::string("gone");
|
||||
};
|
||||
const auto update = [&](const char* action, int n) {
|
||||
return session.ui_command(cmd("request:nu" + std::to_string(n), "news.update", O{{"messageId", id}, {"action", action}}), rev);
|
||||
};
|
||||
update("read", 1);
|
||||
const std::string after_read = folder_of();
|
||||
update("archive", 2);
|
||||
const std::string after_archive = folder_of();
|
||||
update("trash", 3);
|
||||
const std::string after_trash = folder_of();
|
||||
update("restore", 4);
|
||||
const std::string after_restore = folder_of();
|
||||
std::printf("(mailbox %s: %s, %s, %s, %s)\n", id.c_str(), after_read.c_str(), after_archive.c_str(),
|
||||
after_trash.c_str(), after_restore.c_str());
|
||||
check(after_read == "inbox+read" && after_archive == "archive+read" && after_trash == "trash+read" &&
|
||||
after_restore == "inbox+read", "mailbox: read, archive, trash, restore");
|
||||
check(s(at(update("restore", 5), "outcome")) == "no_change", "mailbox: an unchanged mark is no change");
|
||||
check(s(at(session.ui_command(cmd("request:nu6", "news.update", O{{"messageId", "message:none"}, {"action", "read"}}), rev), "code")) ==
|
||||
"unknown_message", "mailbox: unknown message");
|
||||
}
|
||||
}
|
||||
const J few = session.ui_read(O{{"kind", "news"}, {"limit", 3}}, rev);
|
||||
check(at(at(few, "data"), "events").array() && at(at(few, "data"), "events").array()->size() == 3, "news limit");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user