mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 09:40:12 +01:00
ircd:Ⓜ️:push: Move path tuple; add type string suite.
This commit is contained in:
parent
5391ba7b76
commit
2aec995edd
4 changed files with 86 additions and 2 deletions
|
@ -62,6 +62,7 @@ namespace ircd
|
||||||
#include "hook.h"
|
#include "hook.h"
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
#include "invite_3pid.h"
|
#include "invite_3pid.h"
|
||||||
|
#include "push.h"
|
||||||
#include "createroom.h"
|
#include "createroom.h"
|
||||||
#include "room/room.h"
|
#include "room/room.h"
|
||||||
#include "user/user.h"
|
#include "user/user.h"
|
||||||
|
@ -69,7 +70,6 @@ namespace ircd
|
||||||
#include "rooms.h"
|
#include "rooms.h"
|
||||||
#include "rooms_summary.h"
|
#include "rooms_summary.h"
|
||||||
#include "membership.h"
|
#include "membership.h"
|
||||||
#include "push.h"
|
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
|
@ -13,11 +13,20 @@
|
||||||
|
|
||||||
namespace ircd::m::push
|
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 cond;
|
||||||
struct rule;
|
struct rule;
|
||||||
struct rules;
|
struct rules;
|
||||||
struct pusher;
|
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.
|
/// Specification pre-defined defaults.
|
||||||
extern const rules defaults;
|
extern const rules defaults;
|
||||||
}
|
}
|
||||||
|
@ -80,6 +89,8 @@ struct ircd::m::push::rule
|
||||||
json::property<name::pattern, json::string>
|
json::property<name::pattern, json::string>
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
|
static const string_view type_prefix;
|
||||||
|
|
||||||
using super_type::tuple;
|
using super_type::tuple;
|
||||||
using super_type::operator=;
|
using super_type::operator=;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
struct ircd::m::user::pushrules
|
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_bool = std::function<bool ()>;
|
||||||
using closure = std::function<void ()>;
|
using closure = std::function<void ()>;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,79 @@
|
||||||
// copyright notice and this permission notice is present in all copies. The
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
// full license for this software is available in the LICENSE file.
|
// 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)
|
decltype(ircd::m::push::defaults)
|
||||||
ircd::m::push::defaults
|
ircd::m::push::defaults
|
||||||
{R"(
|
{R"(
|
||||||
|
|
Loading…
Add table
Reference in a new issue