mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd:Ⓜ️:user::pushrules: Integrate the default pushrules for the user.
This commit is contained in:
parent
537bdc5e19
commit
28626f17c1
1 changed files with 50 additions and 0 deletions
|
@ -115,6 +115,29 @@ const
|
||||||
path
|
path
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Present the default rules to the closure.
|
||||||
|
if(likely(scope == "global"))
|
||||||
|
{
|
||||||
|
const auto &rules
|
||||||
|
{
|
||||||
|
push::rules::defaults.get<json::array>(kind)
|
||||||
|
};
|
||||||
|
|
||||||
|
for(const json::object &rule : rules)
|
||||||
|
{
|
||||||
|
const json::string &_ruleid
|
||||||
|
{
|
||||||
|
rule["rule_id"]
|
||||||
|
};
|
||||||
|
|
||||||
|
if(_ruleid == ruleid)
|
||||||
|
{
|
||||||
|
closure(path, rule);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char typebuf[event::TYPE_MAX_SIZE];
|
char typebuf[event::TYPE_MAX_SIZE];
|
||||||
const string_view &type
|
const string_view &type
|
||||||
{
|
{
|
||||||
|
@ -155,6 +178,33 @@ const
|
||||||
path
|
path
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If the path contains a ruleid there's at most one item to iterate...
|
||||||
|
if(ruleid)
|
||||||
|
return get(std::nothrow, path, closure);
|
||||||
|
|
||||||
|
// Present the default rules to the closure; note that the for_each
|
||||||
|
// convention dictates if the user's closure returns false we'll never
|
||||||
|
// get past this branch to iterate the default rules.
|
||||||
|
if(!scope || scope == "global")
|
||||||
|
{
|
||||||
|
for(const auto &_kind : json::keys<decltype(push::rules::defaults)>())
|
||||||
|
{
|
||||||
|
if(kind && kind != _kind)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for(const json::object &rule : push::rules::defaults.at<json::array>(_kind))
|
||||||
|
{
|
||||||
|
const push::path path
|
||||||
|
{
|
||||||
|
"global", _kind, json::string{rule["rule_id"]}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!closure(path, rule))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char typebuf[event::TYPE_MAX_SIZE];
|
char typebuf[event::TYPE_MAX_SIZE];
|
||||||
const room::state::type_prefix type
|
const room::state::type_prefix type
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue