diff --git a/modules/console.cc b/modules/console.cc index 38ed1e858..b5f33006d 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -9569,6 +9569,56 @@ console_cmd__room__events(opt &out, const string_view &line) return true; } +bool +console_cmd__room__events__missing(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "room_id" + }}; + + const auto &room_id + { + m::room_id(param.at("room_id")) + }; + + const auto &event_id + { + param[2] + }; + + const m::room room + { + room_id, event_id + }; + + const m::room::events::missing missing + { + room + }; + + missing.for_each([&out] + (const auto &event_id, const auto &ref_depth, const auto &ref_idx) + { + out + << std::right + << std::setw(10) + << ref_idx + << " " + << std::right + << std::setw(8) + << ref_depth + << " " + << std::left + << std::setw(52) + << event_id + << std::endl; + return true; + }); + + return true; +} + bool console_cmd__room__messages(opt &out, const string_view &line) { diff --git a/modules/m_room_events.cc b/modules/m_room_events.cc index de55373ce..e47ba8978 100644 --- a/modules/m_room_events.cc +++ b/modules/m_room_events.cc @@ -179,7 +179,32 @@ IRCD_MODULE_EXPORT ircd::m::room::events::missing::for_each(const closure &closure) const { - return true; + const std::function in_room + { + [this](const string_view &room_id) + { + return room_id == this->room.room_id; + } + }; + + return event::horizon::for_every([&in_room, &closure] + (const event::id &event_id, const event::idx &event_idx) + { + if(!m::query(event_idx, "room_id", false, in_room)) + return true; + + if(m::exists(event_id)) + return true; + + uint64_t depth; + if(!m::get(event_idx, "depth", depth)) + return true; + + if(!closure(event_id, depth, event_idx)) + return false; + + return true; + }); } //