mirror of
https://github.com/matrix-construct/construct
synced 2024-06-20 10:58:20 +02:00
ircd:Ⓜ️:relates: Add reverse iteration; consolidate abi, inline interface.
This commit is contained in:
parent
e2017efcce
commit
c010920f7c
|
@ -38,21 +38,27 @@ struct ircd::m::relates_to
|
|||
///
|
||||
struct ircd::m::relates
|
||||
{
|
||||
event::refs refs;
|
||||
bool match_sender {false};
|
||||
bool prefetch_depth {false};
|
||||
bool prefetch_sender {false};
|
||||
|
||||
public:
|
||||
using closure = util::closure_bool
|
||||
<
|
||||
std::function,
|
||||
const event::idx &, const json::object &, const m::relates_to &
|
||||
>;
|
||||
|
||||
event::refs refs;
|
||||
bool match_sender {false};
|
||||
bool prefetch_depth {false};
|
||||
bool prefetch_sender {false};
|
||||
|
||||
private:
|
||||
bool _each(const string_view &, const closure &, const event::idx &) const;
|
||||
|
||||
public:
|
||||
bool for_each(const string_view &type, const closure &) const;
|
||||
bool for_each(const closure &) const;
|
||||
|
||||
bool rfor_each(const string_view &type, const closure &) const;
|
||||
bool rfor_each(const closure &) const;
|
||||
|
||||
event::idx get(const string_view &type, const uint at = 0) const;
|
||||
event::idx latest(const string_view &type, uint *const at = nullptr) const;
|
||||
|
||||
|
@ -63,3 +69,41 @@ struct ircd::m::relates
|
|||
size_t count(const string_view &type = {}) const;
|
||||
bool prefetch(const string_view &type = {}) const;
|
||||
};
|
||||
|
||||
inline bool
|
||||
ircd::m::relates::rfor_each(const closure &closure)
|
||||
const
|
||||
{
|
||||
return rfor_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::m::relates::rfor_each(const string_view &rel_type,
|
||||
const closure &closure)
|
||||
const
|
||||
{
|
||||
return refs.rfor_each(dbs::ref::M_RELATES, [this, &rel_type, &closure]
|
||||
(const auto &event_idx, const auto &type)
|
||||
{
|
||||
return _each(rel_type, closure, event_idx);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::m::relates::for_each(const closure &closure)
|
||||
const
|
||||
{
|
||||
return for_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::m::relates::for_each(const string_view &rel_type,
|
||||
const closure &closure)
|
||||
const
|
||||
{
|
||||
return refs.for_each(dbs::ref::M_RELATES, [this, &rel_type, &closure]
|
||||
(const auto &event_idx, const auto &type)
|
||||
{
|
||||
return _each(rel_type, closure, event_idx);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -82,13 +82,6 @@ const
|
|||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::relates::for_each(const closure &closure)
|
||||
const
|
||||
{
|
||||
return for_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
ircd::m::event::idx
|
||||
ircd::m::relates::latest(const string_view &type,
|
||||
uint *const at)
|
||||
|
@ -143,47 +136,44 @@ const
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::relates::for_each(const string_view &rel_type,
|
||||
const closure &closure)
|
||||
ircd::m::relates::_each(const string_view &rel_type,
|
||||
const closure &closure,
|
||||
const event::idx &event_idx)
|
||||
const
|
||||
{
|
||||
return refs.for_each(dbs::ref::M_RELATES, [this, &rel_type, &closure]
|
||||
(const auto &event_idx, const auto &type)
|
||||
thread_local char buf[event::MAX_SIZE];
|
||||
const json::object content
|
||||
{
|
||||
thread_local char buf[event::MAX_SIZE];
|
||||
const json::object content
|
||||
{
|
||||
m::get(std::nothrow, event_idx, "content", buf)
|
||||
};
|
||||
m::get(std::nothrow, event_idx, "content", buf)
|
||||
};
|
||||
|
||||
if(!content)
|
||||
if(!content)
|
||||
return true;
|
||||
|
||||
m::relates_to relates
|
||||
{
|
||||
content["m.relates_to"]
|
||||
};
|
||||
|
||||
if(!json::get<"rel_type"_>(relates))
|
||||
if(json::get<"m.in_reply_to"_>(relates))
|
||||
json::get<"rel_type"_>(relates) = "m.in_reply_to";
|
||||
|
||||
if(rel_type)
|
||||
if(json::get<"rel_type"_>(relates) != rel_type)
|
||||
return true;
|
||||
|
||||
m::relates_to relates
|
||||
if(match_sender)
|
||||
{
|
||||
const pair<event::idx> idx
|
||||
{
|
||||
content["m.relates_to"]
|
||||
refs.idx, event_idx
|
||||
};
|
||||
|
||||
if(!json::get<"rel_type"_>(relates))
|
||||
if(json::get<"m.in_reply_to"_>(relates))
|
||||
json::get<"rel_type"_>(relates) = "m.in_reply_to";
|
||||
const std::equal_to<string_view> equal_to;
|
||||
if(!m::query(std::nothrow, idx, "sender", equal_to))
|
||||
return true;
|
||||
}
|
||||
|
||||
if(rel_type)
|
||||
if(json::get<"rel_type"_>(relates) != rel_type)
|
||||
return true;
|
||||
|
||||
if(this->match_sender)
|
||||
{
|
||||
const pair<event::idx> idx
|
||||
{
|
||||
refs.idx, event_idx
|
||||
};
|
||||
|
||||
const std::equal_to<string_view> equal_to;
|
||||
if(!m::query(std::nothrow, idx, "sender", equal_to))
|
||||
return true;
|
||||
}
|
||||
|
||||
return closure(event_idx, content, relates);
|
||||
});
|
||||
return closure(event_idx, content, relates);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue