0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd:Ⓜ️:events: Add type-based iteration w/ console cmd.

This commit is contained in:
Jason Volk 2019-04-16 15:36:44 -07:00
parent fb199fbc01
commit 5fee4a9933
3 changed files with 73 additions and 6 deletions

View file

@ -15,8 +15,10 @@ namespace ircd::m::events
{ {
struct range; struct range;
using closure_bool = std::function<bool (const event::idx &, const event &)>; using closure_bool = std::function<bool (const event::idx &, const event &)>;
using closure_type_bool = std::function<bool (const string_view &, const event::idx &)>;
using closure_sender_bool = std::function<bool (const id::user &, const event::idx &)>; using closure_sender_bool = std::function<bool (const id::user &, const event::idx &)>;
bool for_each_in_type(const string_view &, const closure_type_bool &);
bool for_each_in_sender(const id::user &, const closure_sender_bool &); bool for_each_in_sender(const id::user &, const closure_sender_bool &);
bool for_each_in_origin(const string_view &, const closure_sender_bool &); bool for_each_in_origin(const string_view &, const closure_sender_bool &);

View file

@ -2712,6 +2712,40 @@ ircd::m::events::for_each_in_sender(const id::user &user,
return true; return true;
} }
bool
ircd::m::events::for_each_in_type(const string_view &type,
const closure_type_bool &closure)
{
auto &column
{
dbs::event_type
};
char buf[dbs::EVENT_TYPE_KEY_MAX_SIZE];
const string_view &key
{
dbs::event_type_key(buf, type)
};
auto it
{
column.begin(key)
};
for(; bool(it); ++it)
{
const auto &keyp
{
dbs::event_type_key(it->first)
};
if(!closure(type, std::get<0>(keyp)))
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
// m/filter.h // m/filter.h

View file

@ -5766,7 +5766,7 @@ console_cmd__events__in__origin(opt &out, const string_view &line)
const string_view &origin const string_view &origin
{ {
param.at("origin") lstrip(param.at("origin"), ':')
}; };
m::events::for_each_in_origin(origin, [&out] m::events::for_each_in_origin(origin, [&out]
@ -5790,6 +5790,40 @@ console_cmd__events__in__origin(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__events__in__type(opt &out, const string_view &line)
{
const params param{line, " ",
{
"type"
}};
const string_view &type
{
param.at("type")
};
m::events::for_each_in_type(type, [&out]
(const string_view &type, const m::event::idx &event_idx)
{
const m::event::fetch event
{
event_idx, std::nothrow
};
if(!event.valid)
{
out << event_idx << " " << "NOT FOUND" << std::endl;
return true;
}
out << event_idx << " " << pretty_oneline(event) << std::endl;;
return true;
});
return true;
}
bool bool
console_cmd__events__in(opt &out, const string_view &line) console_cmd__events__in(opt &out, const string_view &line)
{ {
@ -5806,13 +5840,10 @@ console_cmd__events__in(opt &out, const string_view &line)
if(valid(m::id::USER, what)) if(valid(m::id::USER, what))
return console_cmd__events__in__sender(out, line); return console_cmd__events__in__sender(out, line);
if(rfc3986::valid_host(std::nothrow, what)) if(startswith(what, ':') && rfc3986::valid_host(std::nothrow, lstrip(what, ':')))
return console_cmd__events__in__origin(out, line); return console_cmd__events__in__origin(out, line);
throw error return console_cmd__events__in__type(out, line);
{
"Cannot interpret type of argument '%s'", what
};
} }
conf::item<size_t> conf::item<size_t>