mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️:events::relates: Interface to scan the rel_type of the M_RELATES ref type.
This commit is contained in:
parent
9564d8fcdd
commit
e2d70f249f
3 changed files with 121 additions and 0 deletions
|
@ -93,6 +93,21 @@ namespace ircd::m::events::refs
|
|||
bool for_each(const range &, const closure &);
|
||||
}
|
||||
|
||||
/// Interface to scan the rel_type of the M_RELATES refs type
|
||||
namespace ircd::m::events::relates
|
||||
{
|
||||
// (source, rel_type, target)
|
||||
using closure = util::closure_bool
|
||||
<
|
||||
std::function,
|
||||
const event::idx &, const m::relates_to &, const event::idx &
|
||||
>;
|
||||
|
||||
// Iterate events in range
|
||||
bool for_each(const range &, const string_view &rel_type, const closure &);
|
||||
bool for_each(const range &, const closure &);
|
||||
}
|
||||
|
||||
/// Interface to scan the content of events
|
||||
namespace ircd::m::events::content
|
||||
{
|
||||
|
@ -128,6 +143,13 @@ struct ircd::m::events::range
|
|||
{}
|
||||
};
|
||||
|
||||
inline bool
|
||||
ircd::m::events::relates::for_each(const range &range,
|
||||
const closure &closure)
|
||||
{
|
||||
return for_each(range, string_view{}, closure);
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::m::events::origin::for_each(const closure_name &closure)
|
||||
{
|
||||
|
|
|
@ -407,6 +407,41 @@ ircd::m::events::content::for_each(const closure &closure)
|
|||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// events::relates
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::m::events::relates::for_each(const range &range,
|
||||
const string_view &rel_type,
|
||||
const closure &closure)
|
||||
{
|
||||
return refs::for_each(range, [&rel_type, &closure]
|
||||
(const event::idx &src, const dbs::ref &type, const event::idx &tgt)
|
||||
{
|
||||
if(type != dbs::ref::M_RELATES)
|
||||
return true;
|
||||
|
||||
const m::relates rels
|
||||
{
|
||||
src
|
||||
};
|
||||
|
||||
bool ret(true);
|
||||
rels.for_each(rel_type, [&closure, &rel_type, &src, &tgt, &ret]
|
||||
(const event::idx &_tgt, const json::object &, const m::relates_to &relates_to)
|
||||
{
|
||||
if(_tgt != tgt)
|
||||
return true;
|
||||
|
||||
ret = closure(src, relates_to, tgt);
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// events::refs
|
||||
//
|
||||
|
|
|
@ -7972,6 +7972,70 @@ console_cmd__events__refs(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__events__relates(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"start", "stop", "type"
|
||||
}};
|
||||
|
||||
const m::event::idx start
|
||||
{
|
||||
param.at("start", 0UL)
|
||||
};
|
||||
|
||||
const m::event::idx stop
|
||||
{
|
||||
param.at("stop", m::vm::sequence::retired + 1)
|
||||
};
|
||||
|
||||
const string_view &typestr
|
||||
{
|
||||
param.at("type", "*"_sv)
|
||||
};
|
||||
|
||||
const string_view &type
|
||||
{
|
||||
typestr == "*"?
|
||||
string_view{}:
|
||||
typestr
|
||||
};
|
||||
|
||||
m::events::relates::for_each({start, stop}, type, [&out]
|
||||
(const m::event::idx &src, const m::relates_to &relates, const m::event::idx &tgt)
|
||||
{
|
||||
const string_view &rel_type
|
||||
{
|
||||
json::get<"rel_type"_>(relates)
|
||||
};
|
||||
|
||||
const auto src_id
|
||||
{
|
||||
m::event_id(std::nothrow, src)
|
||||
};
|
||||
|
||||
const auto tgt_id
|
||||
{
|
||||
m::event_id(std::nothrow, tgt)
|
||||
};
|
||||
|
||||
out
|
||||
<< ' ' << std::right << std::setw(10) << src
|
||||
<< ' ' << std::left << std::setw(45) << trunc(src_id? string_view{src_id}: "<index error>"_sv, 45)
|
||||
<< " <- "
|
||||
<< ' ' << std::right << std::setw(10) << tgt
|
||||
<< ' ' << std::left << std::setw(45) << trunc(tgt_id? string_view{tgt_id}: "<index error>"_sv, 45)
|
||||
<< ' ' << std::right << rel_type
|
||||
<< std::endl
|
||||
;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__events__dump(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue