mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 15:04:10 +01:00
ircd:Ⓜ️:filter: Add overloads to match() w/ fetch from event_idx.
This commit is contained in:
parent
e2e0b6294f
commit
994702b32f
2 changed files with 61 additions and 0 deletions
|
@ -20,7 +20,10 @@ namespace ircd::m
|
|||
struct state_filter;
|
||||
|
||||
bool match(const event_filter &, const event &);
|
||||
bool match(const event_filter &, const event::idx &);
|
||||
|
||||
bool match(const room_event_filter &, const event &);
|
||||
bool match(const room_event_filter &, const event::idx &);
|
||||
}
|
||||
|
||||
/// 5.1 "Filter" we use event_filter here
|
||||
|
|
|
@ -13,6 +13,38 @@
|
|||
// m/filter.h
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::m::match(const room_event_filter &filter,
|
||||
const event::idx &event_idx)
|
||||
{
|
||||
m::event::keys::include include_keys;
|
||||
|
||||
if(json::get<"contains_url"_>(filter))
|
||||
include_keys.set("content");
|
||||
|
||||
if(json::get<"rooms"_>(filter) || json::get<"not_rooms"_>(filter))
|
||||
include_keys.set("room_id");
|
||||
|
||||
if(json::get<"types"_>(filter) || json::get<"not_types"_>(filter))
|
||||
include_keys.set("type");
|
||||
|
||||
if(json::get<"senders"_>(filter) || json::get<"not_senders"_>(filter))
|
||||
include_keys.set("sender");
|
||||
|
||||
const m::event::fetch event
|
||||
{
|
||||
std::nothrow, event_idx, m::event::fetch::opts
|
||||
{
|
||||
include_keys,
|
||||
}
|
||||
};
|
||||
|
||||
if(unlikely(!event.valid))
|
||||
return false;
|
||||
|
||||
return match(filter, event);
|
||||
}
|
||||
|
||||
//TODO: globular expression
|
||||
//TODO: tribool for contains_url; we currently ignore the false value.
|
||||
bool
|
||||
|
@ -37,6 +69,32 @@ ircd::m::match(const room_event_filter &filter,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::match(const event_filter &filter,
|
||||
const event::idx &event_idx)
|
||||
{
|
||||
m::event::keys::include include_keys;
|
||||
|
||||
if(json::get<"types"_>(filter) || json::get<"not_types"_>(filter))
|
||||
include_keys.set("type");
|
||||
|
||||
if(json::get<"senders"_>(filter) || json::get<"not_senders"_>(filter))
|
||||
include_keys.set("sender");
|
||||
|
||||
const m::event::fetch event
|
||||
{
|
||||
std::nothrow, event_idx, m::event::fetch::opts
|
||||
{
|
||||
include_keys,
|
||||
}
|
||||
};
|
||||
|
||||
if(unlikely(!event.valid))
|
||||
return false;
|
||||
|
||||
return match(filter, event);
|
||||
}
|
||||
|
||||
//TODO: globular expression
|
||||
bool
|
||||
ircd::m::match(const event_filter &filter,
|
||||
|
|
Loading…
Reference in a new issue