mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 07:20:55 +01:00
ircd:Ⓜ️ Replace is_complete w/ sounding(); console cmd.
This commit is contained in:
parent
ba797778d6
commit
486ca09153
4 changed files with 56 additions and 28 deletions
|
@ -28,7 +28,9 @@ namespace ircd::m
|
|||
using depth_range_closure = std::function<bool (const depth_range &, const event::idx &)>;
|
||||
bool for_each_depth_gap(const room &, const depth_range_closure &);
|
||||
bool rfor_each_depth_gap(const room &, const depth_range_closure &);
|
||||
std::pair<bool, int64_t> is_complete(const room &);
|
||||
|
||||
std::pair<int64_t, event::idx> first_missing(const room &);
|
||||
std::pair<int64_t, event::idx> sounding(const room &); // Last missing
|
||||
}
|
||||
|
||||
/// Interface to room messages
|
||||
|
|
35
ircd/m.cc
35
ircd/m.cc
|
@ -4779,6 +4779,28 @@ ircd::m::commit(const room &room,
|
|||
return eval.event_id;
|
||||
}
|
||||
|
||||
std::pair<int64_t, ircd::m::event::idx>
|
||||
ircd::m::sounding(const room &r)
|
||||
{
|
||||
static mods::import<decltype(sounding)> call
|
||||
{
|
||||
"m_room", "ircd::m::sounding"
|
||||
};
|
||||
|
||||
return call(r);
|
||||
}
|
||||
|
||||
std::pair<int64_t, ircd::m::event::idx>
|
||||
ircd::m::first_missing(const room &r)
|
||||
{
|
||||
static mods::import<decltype(first_missing)> call
|
||||
{
|
||||
"m_room", "ircd::m::first_missing"
|
||||
};
|
||||
|
||||
return call(r);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::rfor_each_depth_gap(const room &r,
|
||||
const depth_range_closure &c)
|
||||
|
@ -4807,19 +4829,6 @@ ircd::m::for_each_depth_gap(const room &r,
|
|||
return call(r, c);
|
||||
}
|
||||
|
||||
std::pair<bool, int64_t>
|
||||
ircd::m::is_complete(const room &r)
|
||||
{
|
||||
using prototype = std::pair<bool, int64_t> (const room &);
|
||||
|
||||
static mods::import<prototype> call
|
||||
{
|
||||
"m_room", "ircd::m::is_complete"
|
||||
};
|
||||
|
||||
return call(r);
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::count_since(const m::event::id &a,
|
||||
const m::event::id &b)
|
||||
|
|
|
@ -7371,7 +7371,7 @@ console_cmd__room__head__reset(opt &out, const string_view &line)
|
|||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__complete(opt &out, const string_view &line)
|
||||
console_cmd__room__sounding(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
|
@ -7390,12 +7390,12 @@ console_cmd__room__complete(opt &out, const string_view &line)
|
|||
|
||||
const auto res
|
||||
{
|
||||
m::is_complete(room)
|
||||
m::sounding(room)
|
||||
};
|
||||
|
||||
out << (res.first? "YES" : "NO")
|
||||
<< " @ depth " << res.second
|
||||
<< std::endl;
|
||||
out << "depth: " << res.first << std::endl
|
||||
<< "event: " << res.second << " " << m::event_id(res.second) << std::endl
|
||||
;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -477,21 +477,38 @@ ircd::m::room::head::for_each(const head &head,
|
|||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, int64_t>
|
||||
std::pair<int64_t, ircd::m::event::idx>
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::is_complete(const room &room)
|
||||
ircd::m::sounding(const room &room)
|
||||
{
|
||||
std::pair<bool, int64_t> ret {true, -1L};
|
||||
for_each_depth_gap(room, [&ret]
|
||||
(const auto &range)
|
||||
std::pair<int64_t, m::event::idx> ret
|
||||
{
|
||||
ret.second = range.second - 1;
|
||||
ret.first = false;
|
||||
-1, 0
|
||||
};
|
||||
|
||||
rfor_each_depth_gap(room, [&ret]
|
||||
(const auto &range, const auto &event_idx)
|
||||
{
|
||||
ret.first = range.second;
|
||||
ret.second = event_idx;
|
||||
return false;
|
||||
});
|
||||
|
||||
if(ret.second == -1L)
|
||||
ret.first = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::pair<int64_t, ircd::m::event::idx>
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::first_missing(const room &room)
|
||||
{
|
||||
std::pair<int64_t, m::event::idx> ret {0, 0};
|
||||
for_each_depth_gap(room, [&ret]
|
||||
(const auto &range, const auto &event_idx)
|
||||
{
|
||||
ret.first = range.first;
|
||||
ret.second = event_idx;
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue