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

ircd:Ⓜ️:push: Move path tuple; add type string suite.

This commit is contained in:
Jason Volk 2020-03-18 13:18:04 -07:00
parent 5391ba7b76
commit 2aec995edd
4 changed files with 86 additions and 2 deletions

View file

@ -62,6 +62,7 @@ namespace ircd
#include "hook.h"
#include "vm.h"
#include "invite_3pid.h"
#include "push.h"
#include "createroom.h"
#include "room/room.h"
#include "user/user.h"
@ -69,7 +70,6 @@ namespace ircd
#include "rooms.h"
#include "rooms_summary.h"
#include "membership.h"
#include "push.h"
#include "filter.h"
#include "events.h"
#include "node.h"

View file

@ -13,11 +13,20 @@
namespace ircd::m::push
{
IRCD_M_EXCEPTION(m::error, error, http::INTERNAL_SERVER_ERROR)
IRCD_M_EXCEPTION(error, NOT_A_RULE, http::BAD_REQUEST)
struct cond;
struct rule;
struct rules;
struct pusher;
/// scope, kind, ruleid
using path = std::tuple<string_view, string_view, string_view>;
string_view make_type(const mutable_buffer &, const path &);
path make_path(const string_view &type, const string_view &state_key);
path make_path(const event &);
/// Specification pre-defined defaults.
extern const rules defaults;
}
@ -80,6 +89,8 @@ struct ircd::m::push::rule
json::property<name::pattern, json::string>
>
{
static const string_view type_prefix;
using super_type::tuple;
using super_type::operator=;
};

View file

@ -13,7 +13,7 @@
struct ircd::m::user::pushrules
{
using path = std::tuple<string_view, string_view, string_view>; // path, kind, ruleid
using path = push::path;
using closure_bool = std::function<bool ()>;
using closure = std::function<void ()>;

View file

@ -8,6 +8,79 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
decltype(ircd::m::push::rule::type_prefix)
ircd::m::push::rule::type_prefix
{
"ircd.push.rule"
};
ircd::m::push::path
ircd::m::push::make_path(const event &event)
{
return make_path(at<"type"_>(event), at<"state_key"_>(event));
}
ircd::m::push::path
ircd::m::push::make_path(const string_view &type,
const string_view &state_key)
{
if(unlikely(!startswith(type, rule::type_prefix)))
throw NOT_A_RULE
{
"Type '%s' does not start with prefix '%s'",
type,
rule::type_prefix,
};
const auto unprefixed
{
lstrip(lstrip(type, rule::type_prefix), '.')
};
const auto &[scope, kind]
{
split(unprefixed, '.')
};
return path
{
scope, kind, state_key
};
}
ircd::string_view
ircd::m::push::make_type(const mutable_buffer &buf,
const path &path)
{
const auto &[scope, kind, ruleid]
{
path
};
if(!scope)
return fmt::sprintf
{
buf, "%s.",
rule::type_prefix,
};
else if(!kind)
return fmt::sprintf
{
buf, "%s.%s.",
rule::type_prefix,
scope,
};
return fmt::sprintf
{
buf, "%s.%s.%s",
rule::type_prefix,
scope,
kind,
};
}
decltype(ircd::m::push::defaults)
ircd::m::push::defaults
{R"(