diff --git a/include/ircd/m/room/messages.h b/include/ircd/m/room/messages.h index bbccdeea7..0f0dd3be1 100644 --- a/include/ircd/m/room/messages.h +++ b/include/ircd/m/room/messages.h @@ -28,7 +28,9 @@ namespace ircd::m using depth_range_closure = std::function; bool for_each_depth_gap(const room &, const depth_range_closure &); bool rfor_each_depth_gap(const room &, const depth_range_closure &); - std::pair is_complete(const room &); + + std::pair first_missing(const room &); + std::pair sounding(const room &); // Last missing } /// Interface to room messages diff --git a/ircd/m.cc b/ircd/m.cc index 7ae85816c..4e8db89a7 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -4779,6 +4779,28 @@ ircd::m::commit(const room &room, return eval.event_id; } +std::pair +ircd::m::sounding(const room &r) +{ + static mods::import call + { + "m_room", "ircd::m::sounding" + }; + + return call(r); +} + +std::pair +ircd::m::first_missing(const room &r) +{ + static mods::import 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 -ircd::m::is_complete(const room &r) -{ - using prototype = std::pair (const room &); - - static mods::import 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) diff --git a/modules/console.cc b/modules/console.cc index 4bc5c9e8c..c86baafc3 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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; } diff --git a/modules/m_room.cc b/modules/m_room.cc index 765e59b6b..2de88d0da 100644 --- a/modules/m_room.cc +++ b/modules/m_room.cc @@ -477,21 +477,38 @@ ircd::m::room::head::for_each(const head &head, return true; } -std::pair +std::pair IRCD_MODULE_EXPORT -ircd::m::is_complete(const room &room) +ircd::m::sounding(const room &room) { - std::pair ret {true, -1L}; - for_each_depth_gap(room, [&ret] - (const auto &range) + std::pair 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 +IRCD_MODULE_EXPORT +ircd::m::first_missing(const room &room) +{ + std::pair 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; }