0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

modules/client/directory/user: Modernize user directory query term interpretation.

This commit is contained in:
Jason Volk 2019-06-05 01:12:55 -07:00
parent 1a48bc3899
commit 9662d195cf

View file

@ -29,9 +29,9 @@ resource::response
post__search(client &client,
const resource::request &request)
{
const auto &search_term
const json::string &search_term
{
unquote(request.at("search_term"))
request.at("search_term")
};
const ushort &limit
@ -39,23 +39,19 @@ post__search(client &client,
request.get<ushort>("limit", 10)
};
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] {'@'};
char qbuf[256] {'@', '\0'};
const string_view &query
{
!startswith(search_term, '@')?
string_view{qbuf, strlcpy(qbuf+1, search_term, sizeof(qbuf))}:
search_term
string_view{strlcat{qbuf, search_term}}:
string_view{search_term}
};
bool limited{true};
std::vector<json::value> results;
const m::room::state &users{m::user::users};
users.for_each("ircd.user", query, [&results, &limit, &limited]
(const m::event &event)
{