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

ircd:Ⓜ️:push: Add non-spec condition kind 'contains_user_mxid'.

This commit is contained in:
Jason Volk 2020-03-22 16:38:04 -07:00
parent aeefb8a155
commit f58cfed6e9
2 changed files with 54 additions and 2 deletions

View file

@ -37,8 +37,8 @@ struct ircd::m::push::match
struct opts;
using cond_kind_func = bool (*)(const event &, const cond &, const opts &);
static string_view cond_kind_name[4];
static const cond_kind_func cond_kind[5];
static string_view cond_kind_name[5];
static const cond_kind_func cond_kind[6];
explicit match(const event &, const cond &, const opts &);
explicit match(const event &, const rule &, const opts &);

View file

@ -35,6 +35,7 @@ namespace ircd::m::push
static bool unknown_condition_kind(const event &, const cond &, const match::opts &);
static bool sender_notification_permission(const event &, const cond &, const match::opts &);
static bool contains_display_name(const event &, const cond &, const match::opts &);
static bool contains_user_mxid(const event &, const cond &, const match::opts &);
static bool room_member_count(const event &, const cond &, const match::opts &);
static bool event_match(const event &, const cond &, const match::opts &);
}
@ -44,6 +45,7 @@ ircd::m::push::match::cond_kind
{
event_match,
room_member_count,
contains_user_mxid,
contains_display_name,
sender_notification_permission,
unknown_condition_kind,
@ -54,6 +56,7 @@ ircd::m::push::match::cond_kind_name
{
"event_match",
"room_member_count",
"contains_user_mxid",
"contains_display_name",
"sender_notification_permission",
};
@ -167,6 +170,49 @@ catch(const std::exception &e)
return false;
}
bool
ircd::m::push::contains_user_mxid(const event &event,
const cond &cond,
const match::opts &opts)
try
{
assert(json::get<"kind"_>(cond) == "contains_user_mxid");
const json::object &content
{
json::get<"content"_>(event)
};
const json::string &body
{
content["body"]
};
if(!body)
return false;
assert(opts.user_id);
if(unlikely(!opts.user_id))
return false;
return has(body, opts.user_id);
}
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &e)
{
log::error
{
log, "Push condition 'contains_user_mxid' %s :%s",
string_view{event.event_id},
e.what(),
};
return false;
}
bool
ircd::m::push::contains_display_name(const event &event,
const cond &cond,
@ -707,6 +753,12 @@ ircd::m::push::rules::defaults{R"(
"rule_id": ".m.rule.contains_user_name",
"default": true,
"enabled": true,
"conditions":
[
{
"kind": "contains_user_mxid"
}
],
"actions":
[
"notify",