mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd:Ⓜ️ 5 Filter (m::event_filter) matching (without globular).
This commit is contained in:
parent
ea8dcdf619
commit
d89eaf338c
2 changed files with 42 additions and 0 deletions
|
@ -19,8 +19,11 @@ namespace ircd::m
|
|||
struct room_filter;
|
||||
struct event_filter;
|
||||
struct room_event_filter;
|
||||
|
||||
bool match(const event_filter &, const event &);
|
||||
}
|
||||
|
||||
/// 5.1 "Filter" we use event_filter here
|
||||
struct ircd::m::event_filter
|
||||
:json::tuple
|
||||
<
|
||||
|
@ -35,6 +38,7 @@ struct ircd::m::event_filter
|
|||
using super_type::operator=;
|
||||
};
|
||||
|
||||
/// 5.1 "RoomEventFilter"
|
||||
struct ircd::m::room_event_filter
|
||||
:json::tuple
|
||||
<
|
||||
|
@ -51,6 +55,7 @@ struct ircd::m::room_event_filter
|
|||
using super_type::operator=;
|
||||
};
|
||||
|
||||
/// 5.1 "RoomFilter"
|
||||
struct ircd::m::room_filter
|
||||
:json::tuple
|
||||
<
|
||||
|
|
|
@ -10,6 +10,43 @@
|
|||
|
||||
#include <ircd/m/m.h>
|
||||
|
||||
//TODO: globular expression
|
||||
bool
|
||||
ircd::m::match(const event_filter &filter,
|
||||
const event &event)
|
||||
{
|
||||
for(const auto &type : json::get<"not_types"_>(filter))
|
||||
if(at<"type"_>(event) == unquote(type))
|
||||
return false;
|
||||
|
||||
for(const auto &sender : json::get<"not_senders"_>(filter))
|
||||
if(at<"sender"_>(event) == unquote(sender))
|
||||
return false;
|
||||
|
||||
if(empty(json::get<"senders"_>(filter)) && empty(json::get<"types"_>(filter)))
|
||||
return true;
|
||||
|
||||
if(empty(json::get<"senders"_>(filter)))
|
||||
{
|
||||
for(const auto &type : json::get<"types"_>(filter))
|
||||
if(at<"type"_>(event) == unquote(type))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty(json::get<"types"_>(filter)))
|
||||
{
|
||||
for(const auto &sender : json::get<"senders"_>(filter))
|
||||
if(at<"sender"_>(event) == unquote(sender))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ircd::m::filter::filter(const user &user,
|
||||
const string_view &filter_id,
|
||||
const mutable_buffer &buf)
|
||||
|
|
Loading…
Reference in a new issue