0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 21:59:02 +02:00

modules/client/directory/user: Implement user directory result query.

This commit is contained in:
Jason Volk 2018-02-23 19:36:40 -08:00
parent 924d86e1e9
commit 6385759769

View file

@ -34,13 +34,39 @@ post__search(client &client,
unquote(request.at("search_term"))
};
const auto &limit
const ushort &limit
{
request.get<ushort>("limit", 10)
};
const bool limited{false};
m::room::state users
{
m::user::users
};
// Search term in this endpoint comes in as-is from Riot. Our query
// is a lower_bound of a user_id, so we have to prefix the '@'.
char qbuf[256] {'@'};
const string_view &query
{
!startswith(search_term, '@')?
string_view{qbuf, strlcpy(qbuf+1, search_term, sizeof(qbuf))}:
search_term
};
bool limited{true};
std::vector<json::value> results;
users.test("ircd.user", query, [&results, &limit, &limited]
(const m::event &event)
{
results.emplace_back(json::members
{
{ "user_id", at<"state_key"_>(event) },
});
limited = results.size() >= limit;
return limited; // return true to break
});
return resource::response
{