mirror of https://github.com/djcb/mu.git
server: support 'queries' parameter in 'ping'
Calculate the read/all numbers for matches for a list of queries in :queries. This is used to implement the features where we should those counts for bookmarks.
This commit is contained in:
parent
bdec1fe9c4
commit
aba328c930
|
@ -982,14 +982,33 @@ static void
|
||||||
ping_handler (Context& context, const Parameters& params)
|
ping_handler (Context& context, const Parameters& params)
|
||||||
{
|
{
|
||||||
GError *gerr{};
|
GError *gerr{};
|
||||||
const auto count = mu_store_count(context.store, &gerr);
|
const auto storecount = mu_store_count(context.store, &gerr);
|
||||||
if (count == (unsigned)-1)
|
if (storecount == (unsigned)-1)
|
||||||
throw Error{Error::Code::Store, &gerr, "failed to read store"};
|
throw Error{Error::Code::Store, &gerr, "failed to read store"};
|
||||||
|
|
||||||
|
const auto queries = get_string_vec (params, "queries");
|
||||||
|
|
||||||
|
const auto qresults= [&]() -> std::string {
|
||||||
|
if (queries.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::string res{":queries ("};
|
||||||
|
for (auto&& q: queries) {
|
||||||
|
const auto count{mu_query_count_run (context.query, q.c_str())};
|
||||||
|
const auto unreadq{format("(%s) AND flag:unread", q.c_str())};
|
||||||
|
const auto unread{mu_query_count_run (context.query, unreadq.c_str())};
|
||||||
|
res += format("(:query %s :count %zu :unread %zu)", quoted(q).c_str(), count, unread);
|
||||||
|
}
|
||||||
|
return res + ")";
|
||||||
|
}();
|
||||||
|
|
||||||
print_expr ("(:pong \"" PACKAGE_NAME "\" "
|
print_expr ("(:pong \"" PACKAGE_NAME "\" "
|
||||||
":props ("
|
":props ("
|
||||||
":version \"" VERSION "\" "
|
":version \"" VERSION "\" "
|
||||||
":doccount %u))", count);
|
"%s "
|
||||||
|
":doccount %u))",
|
||||||
|
qresults.c_str(),
|
||||||
|
storecount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1165,7 +1184,9 @@ make_command_map (Context& context)
|
||||||
"create a new maildir",
|
"create a new maildir",
|
||||||
[&](const auto& params){mkdir_handler(context, params);}});
|
[&](const auto& params){mkdir_handler(context, params);}});
|
||||||
cmap.emplace("ping",
|
cmap.emplace("ping",
|
||||||
CommandInfo{{},
|
CommandInfo{
|
||||||
|
ArgMap{ {"queries", ArgInfo{Type::List, false,
|
||||||
|
"queries for which to get read/unread numbers"}}},
|
||||||
"ping the mu-server and get information in response",
|
"ping the mu-server and get information in response",
|
||||||
[&](const auto& params){ping_handler(context, params);}});
|
[&](const auto& params){ping_handler(context, params);}});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue