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:
ClaudeandClaude Opus 5.5 committed 2026-10-29 09:16:57 +01:00
1 parent c361dccd34
commit 179cd970ad
6 files changed
+139 -2

No files matched your search

+35
View File
@@ -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");
}