diff --git a/include/ircd/m/events.h b/include/ircd/m/events.h index 77fad5129..37c7ad9e5 100644 --- a/include/ircd/m/events.h +++ b/include/ircd/m/events.h @@ -19,8 +19,10 @@ namespace ircd::m::events // counts up from start bool for_each(const uint64_t &start, const id_closure_bool &); bool for_each(const uint64_t &start, const closure_bool &); + bool for_each(const uint64_t &start, const event_filter &, const closure_bool &); // -1 starts at newest event; counts down bool rfor_each(const uint64_t &start, const id_closure_bool &); bool rfor_each(const uint64_t &start, const closure_bool &); + bool rfor_each(const uint64_t &start, const event_filter &, const closure_bool &); } diff --git a/include/ircd/m/m.h b/include/ircd/m/m.h index c977350ea..ba66df7dd 100644 --- a/include/ircd/m/m.h +++ b/include/ircd/m/m.h @@ -61,13 +61,13 @@ namespace ircd #include "room.h" #include "user.h" #include "rooms.h" +#include "filter.h" #include "events.h" #include "node.h" #include "login.h" #include "register.h" #include "invite_3pid.h" #include "createroom.h" -#include "filter.h" #include "request.h" #include "v1/v1.h" #include "keys.h" diff --git a/ircd/m/m.cc b/ircd/m/m.cc index a8d2f6a73..d206d9b3e 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -927,6 +927,30 @@ ircd::m::node::room::room(const m::node &node) // m/events.h // +bool +ircd::m::events::rfor_each(const uint64_t &start, + const event_filter &filter, + const closure_bool &closure) +{ + uint limit + { + json::get<"limit"_>(filter)?: 32U + }; + + return rfor_each(start, [&filter, &closure, &limit] + (const event::idx &event_idx, const m::event &event) + -> bool + { + if(!match(filter, event)) + return true; + + if(!closure(event_idx, event)) + return false; + + return --limit; + }); +} + bool ircd::m::events::rfor_each(const uint64_t &start, const closure_bool &closure) @@ -977,6 +1001,30 @@ ircd::m::events::rfor_each(const uint64_t &start, return true; } +bool +ircd::m::events::for_each(const uint64_t &start, + const event_filter &filter, + const closure_bool &closure) +{ + uint limit + { + json::get<"limit"_>(filter)?: 32U + }; + + return for_each(start, [&filter, &closure, &limit] + (const event::idx &event_idx, const m::event &event) + -> bool + { + if(!match(filter, event)) + return true; + + if(!closure(event_idx, event)) + return false; + + return --limit; + }); +} + bool ircd::m::events::for_each(const uint64_t &start, const closure_bool &closure)