Skip to content

Commit

Permalink
ircd::m::push: Implement event_property_contains. (matrix-org/matrix-…
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed Mar 7, 2023
1 parent 0c20fa6 commit 3e9c225
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions matrix/push.cc
Expand Up @@ -77,6 +77,7 @@ namespace ircd::m::push
static bool state_key_user_mxid(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_property_contains(const event &, const cond &, const match::opts &);
static bool event_property_is(const event &, const cond &, const match::opts &);
static bool event_match(const event &, const cond &, const match::opts &);
}
Expand All @@ -86,6 +87,7 @@ ircd::m::push::match::cond_kind
{
event_match,
event_property_is,
event_property_contains,
room_member_count,
contains_user_mxid,
state_key_user_mxid,
Expand All @@ -99,6 +101,7 @@ ircd::m::push::match::cond_kind_name
{
"event_match",
"event_property_is",
"event_property_contains",
"room_member_count",
"contains_user_mxid",
"state_key_user_mxid",
Expand Down Expand Up @@ -245,6 +248,49 @@ catch(const std::exception &e)
return false;
}

bool
ircd::m::push::event_property_contains(const event &event,
const cond &cond,
const match::opts &opts)
try
{
assert(json::get<"kind"_>(cond) == "event_property_contains");

const json::array array
{
value_extract(event, cond)
};

if(!json::type(array, json::ARRAY))
return false;

const json::value a
{
at<"value"_>(cond)
};

for(const json::value b : array)
if(type(a) == type(b) && a == b)
return true;

return false;
}
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &e)
{
log::error
{
log, "Push condition 'event_property_contains' %s :%s",
string_view{event.event_id},
e.what(),
};

return false;
}

bool
ircd::m::push::contains_user_mxid(const event &event,
const cond &cond,
Expand Down

0 comments on commit 3e9c225

Please sign in to comment.