diff --git a/include/ircd/m/vm.h b/include/ircd/m/vm.h index 0841f4612..9e74385ed 100644 --- a/include/ircd/m/vm.h +++ b/include/ircd/m/vm.h @@ -81,6 +81,8 @@ struct ircd::m::vm::eval string_view room_version; static bool for_each_pdu(const std::function &); + static const event *find_pdu(const eval &, const event::id &); + static const event *find_pdu(const event::id &); public: operator const event::id::buf &() const; diff --git a/ircd/m.cc b/ircd/m.cc index c5ce4e318..043fc2886 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -1558,6 +1558,40 @@ const return event_id; } +const ircd::m::event * +ircd::m::vm::eval::find_pdu(const event::id &event_id) +{ + const m::event *ret{nullptr}; + for_each_pdu([&ret, &event_id] + (const m::event &event) + { + if(event.event_id != event_id) + return true; + + ret = std::addressof(event); + return false; + }); + + return ret; +} + +const ircd::m::event * +ircd::m::vm::eval::find_pdu(const eval &eval, + const event::id &event_id) +{ + const m::event *ret{nullptr}; + for(const auto &event : eval.pdus) + { + if(event.event_id != event_id) + continue; + + ret = std::addressof(event); + break; + } + + return ret; +} + bool ircd::m::vm::eval::for_each_pdu(const std::function &closure) {