mirror of
https://github.com/matrix-construct/construct
synced 2025-02-20 02:30:07 +01:00
ircd:Ⓜ️:event::auth: Add iteration by type.
This commit is contained in:
parent
1df1897e6d
commit
2b82dfec76
3 changed files with 87 additions and 5 deletions
|
@ -18,16 +18,26 @@ namespace ircd::m
|
|||
|
||||
struct ircd::m::event::auth
|
||||
{
|
||||
using closure_bool = event::closure_idx_bool;
|
||||
|
||||
event::idx idx;
|
||||
|
||||
public:
|
||||
using closure_bool = event::closure_idx_bool;
|
||||
|
||||
bool for_each(const string_view &type, const closure_bool &) const;
|
||||
bool for_each(const closure_bool &) const;
|
||||
|
||||
bool has(const string_view &type) const noexcept;
|
||||
bool has(const event::idx &) const noexcept;
|
||||
|
||||
size_t count(const string_view &type) const noexcept;
|
||||
size_t count() const noexcept;
|
||||
|
||||
auth(const event::idx &idx) noexcept;
|
||||
auth(const event::idx &idx)
|
||||
:idx{idx}
|
||||
{
|
||||
assert(idx);
|
||||
}
|
||||
};
|
||||
|
||||
inline
|
||||
|
|
|
@ -1132,10 +1132,17 @@ ircd::m::is_power_event(const m::event &event)
|
|||
size_t
|
||||
ircd::m::event::auth::count()
|
||||
const noexcept
|
||||
{
|
||||
return count(string_view{});
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::event::auth::count(const string_view &type)
|
||||
const noexcept
|
||||
{
|
||||
assert(idx);
|
||||
size_t ret(0);
|
||||
for_each([&ret](const auto &)
|
||||
for_each(type, [&ret](const auto &)
|
||||
{
|
||||
++ret;
|
||||
return true;
|
||||
|
@ -1154,9 +1161,31 @@ const noexcept
|
|||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::event::auth::has(const string_view &type)
|
||||
const noexcept
|
||||
{
|
||||
bool ret{false};
|
||||
for_each(type, [&ret](const auto &)
|
||||
{
|
||||
ret = true;
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::event::auth::for_each(const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
return for_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::event::auth::for_each(const string_view &type,
|
||||
const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
auto &column
|
||||
{
|
||||
|
@ -1185,6 +1214,24 @@ const
|
|||
std::get<0>(parts)
|
||||
};
|
||||
|
||||
bool match;
|
||||
const auto matcher
|
||||
{
|
||||
[&type, &match](const string_view &type_)
|
||||
{
|
||||
match = type == type_;
|
||||
}
|
||||
};
|
||||
|
||||
if(type)
|
||||
{
|
||||
if(!m::get(std::nothrow, ref, "type", matcher))
|
||||
continue;
|
||||
|
||||
if(!match)
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(idx != ref);
|
||||
if(!closure(ref))
|
||||
return false;
|
||||
|
|
|
@ -5878,7 +5878,7 @@ console_cmd__event__auth(opt &out, const string_view &line)
|
|||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"event_id"
|
||||
"event_id", "type"
|
||||
}};
|
||||
|
||||
const m::event::id &event_id
|
||||
|
@ -5886,12 +5886,37 @@ console_cmd__event__auth(opt &out, const string_view &line)
|
|||
param.at("event_id")
|
||||
};
|
||||
|
||||
const string_view type
|
||||
{
|
||||
param.at("type", ""_sv)
|
||||
};
|
||||
|
||||
const m::event::auth auth
|
||||
{
|
||||
index(event_id)
|
||||
};
|
||||
|
||||
auth.for_each([&out](const m::event::idx &idx)
|
||||
auth.for_each(type, [&out]
|
||||
(const m::event::idx &idx)
|
||||
{
|
||||
const m::event::fetch event
|
||||
{
|
||||
idx, std::nothrow
|
||||
};
|
||||
|
||||
if(!event.valid)
|
||||
return true;
|
||||
|
||||
out << idx
|
||||
<< " " << pretty_oneline(event)
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
{
|
||||
const m::event::fetch event
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue