0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

modules/client/pushrules: Support the /enabled paths on GET and PUT methods.

This commit is contained in:
Jason Volk 2020-03-18 16:29:42 -07:00
parent 66c4ebfbb4
commit 927da1002e

View file

@ -68,6 +68,29 @@ ircd::m::push::handle_get(client &client,
request.user_id
};
const bool handle_enabled
{
request.parv.size() > 3 &&
request.parv[3] == "enabled"
};
if(handle_enabled)
{
pushrules.get(path, [&]
(const auto &path, const json::object &rule)
{
resource::response
{
client, json::members
{
{ "enabled", rule["enabled"] }
}
};
});
return {}; // returned from closure or threw 404
}
m::resource::response::chunked response
{
client, http::OK
@ -243,6 +266,37 @@ ircd::m::push::handle_put(client &client,
request
};
const bool handle_enabled
{
request.parv.size() > 3 &&
request.parv[3] == "enabled"
};
if(handle_enabled)
{
pushrules.get(path, [&pushrules, &rule]
(const auto &path, const json::object &old_rule)
{
const auto new_rule
{
json::replace(old_rule,
{
"enabled", json::get<"enabled"_>(rule)
})
};
const auto res
{
pushrules.set(path, new_rule)
};
});
return resource::response
{
client, http::OK
};
}
const auto res
{
pushrules.set(path, rule)