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

modules/client: Minor upgrades to std::clamp/std::minmax templates.

This commit is contained in:
Jason Volk 2019-10-10 13:33:43 -07:00
parent ec6c3bbc0f
commit 9bb4936625
5 changed files with 27 additions and 30 deletions

View file

@ -122,14 +122,14 @@ m::resource::response
post__keys_claim(client &client, post__keys_claim(client &client,
const m::resource::request &request) const m::resource::request &request)
{ {
const milliseconds timeout{[&request] const milliseconds
timeout_min{claim_timeout_min},
timeout_max{claim_timeout_max},
timeout_default{claim_timeout_default},
timeout
{ {
const milliseconds _default(claim_timeout_default); std::clamp(request.get("timeout", timeout_default), timeout_min, timeout_max)
milliseconds ret(request.get("timeout", _default)); };
ret = std::max(ret, milliseconds(claim_timeout_min));
ret = std::min(ret, milliseconds(claim_timeout_max));
return ret;
}()};
const json::object &one_time_keys const json::object &one_time_keys
{ {

View file

@ -121,14 +121,14 @@ m::resource::response
post__keys_query(client &client, post__keys_query(client &client,
const m::resource::request &request) const m::resource::request &request)
{ {
const milliseconds timeout{[&request] const milliseconds
timeout_min{query_timeout_min},
timeout_max{query_timeout_max},
timeout_default{query_timeout_default},
timeout
{ {
const milliseconds _default(query_timeout_default); std::clamp(request.get("timeout", timeout_default), timeout_min, timeout_max)
milliseconds ret(request.get("timeout", _default)); };
ret = std::max(ret, milliseconds(query_timeout_min));
ret = std::min(ret, milliseconds(query_timeout_max));
return ret;
}()};
const auto &token const auto &token
{ {

View file

@ -63,11 +63,10 @@ get__context(client &client,
url::decode(event_id, request.parv[2]) url::decode(event_id, request.parv[2])
}; };
const auto limit{[&request] const auto &limit
{ {
auto ret(request.query.get<size_t>("limit", default_limit)); std::min(request.query.get<size_t>("limit", default_limit), size_t(limit_max))
return std::min(ret, size_t(limit_max)); };
}()};
const m::room room const m::room room
{ {

View file

@ -1106,17 +1106,15 @@ try
{ {
uint64_t(lex_cast<int64_t>(next_batch_token?: "-1"_sv)) uint64_t(lex_cast<int64_t>(next_batch_token?: "-1"_sv))
} }
,timesout{[&request] ,timesout
{ {
auto ret std::clamp
{ (
request.query.get("timeout", milliseconds(timeout_default)) request.query.get("timeout", milliseconds(timeout_default)),
}; milliseconds(timeout_min),
milliseconds(timeout_max)
ret = std::min(ret, milliseconds(timeout_max)); )
ret = std::max(ret, milliseconds(timeout_min)); }
return now<system_point>() + ret;
}()}
,full_state ,full_state
{ {
request.query.get("full_state", false) request.query.get("full_state", false)

View file

@ -204,7 +204,7 @@ ircd::m::sync::_notification_count(const room &room,
{ {
const event::idx_range range const event::idx_range range
{ {
std::min(a, b), std::max(a, b) std::minmax(a, b)
}; };
return room::events::count(room, range); return room::events::count(room, range);
@ -223,7 +223,7 @@ ircd::m::sync::_highlight_count(const room &room,
const event::idx_range range const event::idx_range range
{ {
std::min(a, b), std::max(a, b) std::minmax(a, b)
}; };
return highlight.count_between(room, range); return highlight.count_between(room, range);