mirror of https://github.com/djcb/mu.git
server: split off new server command 'queries'
Instead of being part of the ping command, create a separate queries command, which is easier for updating. Ie. 'ping' implies "show main screen" but we don't always want that side-effect.
This commit is contained in:
parent
beb2bef8dd
commit
ef2ec7d5a5
|
@ -98,6 +98,7 @@ struct Server::Private {
|
||||||
void move_handler(const Command& cmd);
|
void move_handler(const Command& cmd);
|
||||||
void mkdir_handler(const Command& cmd);
|
void mkdir_handler(const Command& cmd);
|
||||||
void ping_handler(const Command& cmd);
|
void ping_handler(const Command& cmd);
|
||||||
|
void queries_handler(const Command& cmd);
|
||||||
void quit_handler(const Command& cmd);
|
void quit_handler(const Command& cmd);
|
||||||
void remove_handler(const Command& cmd);
|
void remove_handler(const Command& cmd);
|
||||||
void sent_handler(const Command& cmd);
|
void sent_handler(const Command& cmd);
|
||||||
|
@ -287,17 +288,20 @@ Server::Private::make_command_map()
|
||||||
[&](const auto& params) { mkdir_handler(params); }});
|
[&](const auto& params) { mkdir_handler(params); }});
|
||||||
cmap.emplace(
|
cmap.emplace(
|
||||||
"ping",
|
"ping",
|
||||||
|
CommandInfo{
|
||||||
|
ArgMap{},
|
||||||
|
"ping the mu-server and get server information in the response",
|
||||||
|
[&](const auto& params) { ping_handler(params); }});
|
||||||
|
|
||||||
|
cmap.emplace(
|
||||||
|
"queries",
|
||||||
CommandInfo{
|
CommandInfo{
|
||||||
ArgMap{
|
ArgMap{
|
||||||
{":queries",
|
{":queries",
|
||||||
ArgInfo{Type::List, false, "queries for which to get read/unread numbers"}},
|
ArgInfo{Type::List, false, "queries for which to get read/unread numbers"}},
|
||||||
{":skip-dups",
|
|
||||||
ArgInfo{Type::Symbol,
|
|
||||||
false,
|
|
||||||
"whether to exclude messages with duplicate message-ids"}},
|
|
||||||
},
|
},
|
||||||
"ping the mu-server and get information in response",
|
"get unread/totals information for a list of queries",
|
||||||
[&](const auto& params) { ping_handler(params); }});
|
[&](const auto& params) { queries_handler(params); }});
|
||||||
|
|
||||||
cmap.emplace("quit", CommandInfo{{}, "quit the mu server", [&](const auto& params) {
|
cmap.emplace("quit", CommandInfo{{}, "quit the mu server", [&](const auto& params) {
|
||||||
quit_handler(params);
|
quit_handler(params);
|
||||||
|
@ -916,9 +920,28 @@ Server::Private::ping_handler(const Command& cmd)
|
||||||
const auto storecount{store().size()};
|
const auto storecount{store().size()};
|
||||||
if (storecount == (unsigned)-1)
|
if (storecount == (unsigned)-1)
|
||||||
throw Error{Error::Code::Store, "failed to read store"};
|
throw Error{Error::Code::Store, "failed to read store"};
|
||||||
|
Sexp addrs;
|
||||||
|
for (auto&& addr : store().properties().personal_addresses)
|
||||||
|
addrs.add(addr);
|
||||||
|
|
||||||
|
output_sexp(Sexp()
|
||||||
|
.put_props(":pong", "mu")
|
||||||
|
.put_props(":props",
|
||||||
|
Sexp().put_props(
|
||||||
|
":version", VERSION,
|
||||||
|
":personal-addresses", std::move(addrs),
|
||||||
|
":database-path", store().properties().database_path,
|
||||||
|
":root-maildir", store().properties().root_maildir,
|
||||||
|
":doccount", storecount)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Server::Private::queries_handler(const Command& cmd)
|
||||||
|
{
|
||||||
const auto queries{cmd.string_vec_arg(":queries")
|
const auto queries{cmd.string_vec_arg(":queries")
|
||||||
.value_or(std::vector<std::string>{})};
|
.value_or(std::vector<std::string>{})};
|
||||||
|
|
||||||
Sexp qresults;
|
Sexp qresults;
|
||||||
for (auto&& q : queries) {
|
for (auto&& q : queries) {
|
||||||
const auto count{store_.count_query(q)};
|
const auto count{store_.count_query(q)};
|
||||||
|
@ -929,22 +952,10 @@ Server::Private::ping_handler(const Command& cmd)
|
||||||
":unread", unread));
|
":unread", unread));
|
||||||
}
|
}
|
||||||
|
|
||||||
Sexp addrs;
|
output_sexp(Sexp(":queries"_sym, std::move(qresults)));
|
||||||
for (auto&& addr : store().properties().personal_addresses)
|
|
||||||
addrs.add(addr);
|
|
||||||
|
|
||||||
auto lst = Sexp().put_props(":pong", "mu");
|
|
||||||
auto proplst = Sexp().put_props(
|
|
||||||
":version", VERSION,
|
|
||||||
":personal-addresses", std::move(addrs),
|
|
||||||
":database-path", store().properties().database_path,
|
|
||||||
":root-maildir", store().properties().root_maildir,
|
|
||||||
":doccount", storecount,
|
|
||||||
":queries", std::move(qresults));
|
|
||||||
|
|
||||||
output_sexp(lst.put_props(":props", std::move(proplst)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::Private::quit_handler(const Command& cmd)
|
Server::Private::quit_handler(const Command& cmd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -106,8 +106,7 @@ CommandHandler::invoke(const Command& cmd, bool do_validate) const
|
||||||
const auto cmit{cmap_.find(cmd.name())};
|
const auto cmit{cmap_.find(cmd.name())};
|
||||||
if (cmit == cmap_.cend())
|
if (cmit == cmap_.cend())
|
||||||
return Err(Error::Code::Command,
|
return Err(Error::Code::Command,
|
||||||
"unknown command in command '%s'",
|
"unknown command '%s'", cmd.to_string().c_str());
|
||||||
cmd.to_string().c_str());
|
|
||||||
|
|
||||||
const auto& cmd_info{cmit->second};
|
const auto& cmd_info{cmit->second};
|
||||||
if (do_validate) {
|
if (do_validate) {
|
||||||
|
|
Loading…
Reference in New Issue